What is CSR in React? Client-Side Rendering Explained

This article provides a comprehensive overview of Client-Side Rendering (CSR) in React. You will learn what CSR is, how it works under the hood, its primary advantages and disadvantages, and how it compares to Server-Side Rendering (SSR) so you can make informed decisions for your next web development project.

Understanding Client-Side Rendering (CSR)

Client-Side Rendering (CSR) is a web development method where the browser downloads a minimal HTML document, fetches the required JavaScript files, and compiles and renders the website’s user interface directly in the user’s browser.

In a standard React application created with tools like Vite or Create React App, CSR is the default rendering method. Instead of receiving a fully rendered website from a server, the browser receives a nearly empty HTML file and a JavaScript bundle containing the React library and your application code.

How CSR Works in React

When a user visits a React website using CSR, the following sequence occurs:

  1. The Request: The browser requests a webpage from the server.
  2. The Response: The server sends back a basic, blank HTML file. This file typically contains a single div element (usually with id="root") and a script tag linking to the JavaScript bundle.
  3. Downloading Assets: The browser downloads the referenced JavaScript and CSS files.
  4. Execution and Rendering: The browser executes the React code. React generates the virtual DOM, mounts it to the empty div in the real DOM, and the user finally sees the fully rendered webpage.
  5. Dynamic Updates: As the user interacts with the app, React updates the DOM dynamically without requiring a full page reload.

Key Advantages of CSR in React

Disadvantages of CSR

CSR vs. SSR in React

While CSR renders the application in the user’s browser, Server-Side Rendering (SSR) generates the full HTML on the server for every request and sends it pre-rendered to the browser.