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
- The browser downloads
index.htmlwith an empty<div id="root">. - It downloads and executes the JavaScript bundle.
createRoot(...).render(<App />)renders the UI.- 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 runs2// <div id="root"></div>3// <script type="module" src="/src/main.tsx"></script>45// src/main.tsx6import { StrictMode, useEffect, useState } from "react";7import { createRoot } from "react-dom/client";89function 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 boots13 }, []);14 return <h1>{stats ? `${stats.users} users` : "Loading…"}</h1>;15}1617createRoot(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.