ReactEasy

What is CSR (Client-Side Rendering)?

Client-side rendering means the server sends a minimal HTML shell and a JavaScript bundle, and React builds the entire UI in the browser. It is the classic single-page app model (Vite SPA, old Create React App): simple to host and great for highly interactive apps behind a login, but slower to first content and weaker for SEO.

How it works

  1. The browser downloads index.html with an empty <div id="root">.
  2. It downloads and executes the JavaScript bundle.
  3. createRoot(...).render(<App />) renders the UI.
  4. Components fetch data, so users often see a spinner before content.

Strengths

  • Static hosting only (CDN, S3), no server runtime.
  • Fast navigations after the first load, since everything runs on the client.
  • Simple mental model: no server and client split.

Weaknesses

  • Slower first contentful paint and LCP, especially on slow phones.
  • Data waterfalls: render, then fetch, then render children, then fetch again.
  • SEO and link previews depend on crawlers executing JavaScript.
  • Larger JavaScript bundles.

When it is a good fit

Dashboards, internal tools, apps behind authentication, offline-capable apps, embedded widgets.

Improving a CSR app

  • Code split by route, preload critical chunks.
  • Fetch data with a router loader or TanStack Query at the route level to avoid waterfalls.
  • Prerender public pages, or move them to a framework with SSR or static generation.
  • The React docs recommend frameworks for new apps, but note that frameworks like React Router and Next.js can also output pure SPAs.

Code example

tsx
1// index.html (served as-is): the body is empty until JavaScript runs
2// <div id="root"></div>
3// <script type="module" src="/src/main.tsx"></script>
4
5// src/main.tsx
6import { StrictMode, useEffect, useState } from "react";
7import { createRoot } from "react-dom/client";
8
9function App() {
10 const [stats, setStats] = useState<{ users: number } | null>(null);
11 useEffect(() => {
12 fetch("/api/stats").then((r) => r.json()).then(setStats); // data fetched after JS boots
13 }, []);
14 return <h1>{stats ? `${stats.users} users` : "Loading…"}</h1>;
15}
16
17createRoot(document.getElementById("root")!).render(
18 <StrictMode>
19 <App />
20 </StrictMode>
21);

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app