Exploring Client-Side and Server-Side Rendering

Priyanshu Chauhan
3 min readMay 1, 2024

--

In the world of web application development, the terms Client-Side Rendering (CSR) and Server-Side Rendering (SSR) come up rather frequently. To essentially build quicker, more responsive, and more effective web applications, understanding the fundamental differences between CSR and SSR is key.

Let’s delve into this.

Client-Side Rendering (CSR)

In CSR, the majority of the rendering logic is shifted to the browser. When a user requests a website, only a minimal HTML document with attached JavaScript files is sent from the server to the client.

How does it work? Here’s a simplified step-by-step overview:

1. A user makes a request over the internet to visit a web page.
2. The server sends a response which generally includes an HTML file with links to CSS and JavaScript files — this is a shell page.
3. The client’s browser then fetches and parses these CSS and JavaScript files.
4. The JavaScript performs additional fetch requests to retrieve data (likely from an API) necessary to populate the content on the page.
5. Finally, the browser generates the final HTML content and displays the webpage.

CSR’s major advantage includes the ability to provide a highly dynamic and interactive user experience as everything happens in the browser itself once the initial load is complete. However, CSR’s primary drawback is the initial loading time, which may cause a delay before the user sees any content on the web page, crucial in search engine optimization context.

In terms of SEO, CSR presents an additional challenge due to its asynchronous data loading. When a search engine bot proxies a user’s interaction to crawl a website, it needs to access a fully loaded website for the best outcome. Because CSR initially sends a minimal version of the site, search engines may not accurately index the site. However, modern search engines are evolving and improving at the execution and rendering of JavaScript pages.

Read more about CSR and SPAs at MDN Web Docs

Server-Side Rendering (SSR)

Contrary to CSR, in SSR, the server sends a complete page response to the client. It means the server does most of the “heavy lifting”, including generating the HTML view on the server itself.

Here’s how SSR works in a nutshell:

1. A user makes a request over the internet to view a web page.
2. The server processes this request, fetches data, generates a full HTML response and sends it back to the client’s browser.
3. The client’s browser receives this HTML response, parses it and displays it to the user.
4. If additional interaction is needed, the client’s browser will download and execute JavaScript.

One main benefit of SSR is the quicker initial page load time, as the browser can display the page once it receives the full HTML from the server. The user can start viewing the page while the rest of the assets continue to load. This results in improved SEO as search engine crawlers can easily parse the fully-rendered HTML page.

Furthermore, SSR gives a better user experience for users with low-end devices, slow internet connections, or old browsers. This is because these users are effectively “bypassed” from the need to compile and run JavaScript on their end, thus saving computational resources.

JavaScript frameworks like Next.js and Nuxt.js support SSR in conjunction with React and Vue.js respectively. These frameworks unify the advantages of SSR and CSR by leveraging their strengths based on the days demands of the pages that make up an application.

For a deep dive into SSR and its SEO benefits, check this article by Google Search Central

However, a downside to SSR is the potential for slow page render times and a higher server load. Since the server has to generate a new HTML page for every new request, it may lead to longer waiting times for the user if the server is under heavy load.

Choosing Between CSR and SSR

Knowing when to use CSR or SSR comes down to the specific requirements of your web application. More recently, JavaScript frameworks like Next.js and Nuxt.js support both CSR and SSR, known as Isomorphic or Universal rendering (2).

Learn more about Isomorphic Rendering at Smashing Magazine

References:

  1. Client-side JavaScript frameworks
  2. Dynamic Rendering For JavaScript Sites
  3. Hybrid Static & Server Rendering with Next.js

--

--

Priyanshu Chauhan
Priyanshu Chauhan

Written by Priyanshu Chauhan

Senior Frontend Engineer at Razorpay | JS 🤌🏻

No responses yet