CSR vs SSR vs SSG vs ISR

CSR vs SSR vs SSG vs ISR

ยท

3 min read

In this Blog I will discuss what is the differences between these rendering methods, Each of these methods has its own unique characteristics and use cases, and none is inherently better than the others. Instead, the choice of method depends on the specific requirements of your project.

Let's Discuss these one by one

Client Side Rendering(CSR)

In Client Side Rendering,

  1. The server responds by sending back an HTML page with only a reference to your JavaScript bundle and the CSS styles.

  2. All Downloading this bundle happens in the Browser.

  3. Initially, due to the unavailability of JavaScript, the page may be non-interactive (for a brief moment, which is typically not visible to the end-user).

Here All assembling the things is done via Browser.

Advantages of CSR

  1. Best for SPA (Single Page Applications)

  2. Reduced Server Load

Disadvantage of CSR

  1. Slower Initial Load:

  2. SEO Challenges

Now in the Case of NextJS, all Components are firstly Server Components to make any component Client, we need to use "use client" at the top of the Component.

Server Side Rendering (SSR)

In Server Side Rendering (SSR):

  1. The server responds by sending back a fully-rendered HTML page that includes all the content, data, and styles.

  2. The entire page, including its content and interactivity, is generated on the server and sent to the client as a complete HTML document.

  3. The user immediately sees a fully interactive page without a delay or period of non-interactivity. This is because the server has pre-rendered the page with all the necessary data and content.

So, in SSR, the server handles the rendering of the page on the server side, and the client receives a fully formed HTML page, ensuring that users can interact with the page immediately without any initial non-interactive moments.

Here for every page we request data from the server, if we request page 1, then respond back with page 1.

Advantages of SSR

  1. Better SEO Performance

  2. Improved Performance on Low-End Devices

Disadvantages of SSR

  1. Slower Subsequent Page Loads

  2. Increases Server Load

Basically, all Components in NextJS are Server Component, you do not need to do anything special to make any component Server Component

Static Side Generation

In Static Side Generation (SSG):

To avoid the rendering in each request, we generate the files in the build time, so that we can instantly serve the pages when the user requests it.

For Static Content, we mainly use this technique.

Advantages of SSG

  1. Faster load times

  2. Better SEO

Disadvantages of SSG

  1. Longer build times

  2. Stale data

Incremental Static Regeneration

  1. Similar to Static Site Generation (SSG), ISR initially serves an HTML page that includes pre-rendered content for the requested route.

  2. Like SSG, ISR leverages pre-rendered content for speed and efficiency.

  3. However, ISR distinguishes itself by continually updating this pre-rendered content in the background. This means that the server constantly rebuilds and refreshes the content, keeping it up-to-date.

Advantages of ISG

  1. Faster loading times

  2. Better SEO

Disadvantages of ISG

  1. Slow the first load

  2. Stale data

Each rendering method has its use cases, with CSR for dynamic apps, SSR for immediate interactivity, SSG for speed, and ISR for a balance between speed and real-time data updates. The choice depends on project requirements.

Thanks for reading this

Happy Coding ๐ŸŽ‰

ย