Client-Side Rendering (CSR)
Client-side rendering uses JavaScript in the browser to create or update a route's main interface after its document arrives.
Download Markdown (.md)Soroush’s Product Wiki · https://wiki.soroush.uk/topic/client-side-rendering/
01What it means
Client-side rendering (CSR) produces a view primarily in the browser. An initial HTML document loads JavaScript, the application obtains data, and code creates or changes DOM content. CSR can describe an initial route or later transitions; it does not require that every part of the product use the same rendering method.[1][2]
- 01Document shellHTML, styles, script references
- 02Download codeParse and execute
- 03Establish stateFetch route data
- 04Render DOMCreate or update view
- 05Update locallyState and route changes
CSR may describe the initial route, later transitions, or only part of a hybrid product.
02Why it matters
CSR enables rich stateful interfaces and moves rendering capacity to users' devices, but content and interaction may depend on script download, parsing, execution, and data requests. These costs vary sharply with device and network conditions.
03When to use it
Use CSR for private, interaction-heavy views where data is naturally fetched after authentication and persistent browser state provides value. Avoid making essential content depend on a large client runtime when server or static HTML can deliver it more reliably.
04How it works
- The server returns a document shell and references to scripts and styles.
- The browser downloads, parses, and executes the application code.
- Client code establishes state and requests any data needed for the route.
- The application creates or updates DOM nodes for the current view.
- Later state and route changes trigger targeted client renders.
05A practical example
An internal analytics workspace renders charts after the signed-in browser obtains user-specific data. The team keeps the sign-in and error pages server-rendered, splits the chart code, and provides clear loading and retry states.
06Where it breaks
Initial content can be delayed by JavaScript and request waterfalls, low-powered devices pay execution cost, and script failure can leave an empty shell. Search and sharing behavior may require separate handling, and complex client state creates debugging overhead.
Common mistakes
- Assuming client rendering is fast because navigation feels quick on a development laptop.
- Shipping one large bundle before showing essential content.
- Leaving an empty page when scripts or data requests fail.
- Using CSR for every route instead of choosing rendering per user need.
07Sources
- Rendering on the Webweb.dev · Official technical guidanceRendering on the Web
- Client-side web APIsMDN Web Docs · Official technical documentationClient-side web APIs