Rendering Strategies
CSR, SSR, SSG, ISR, streaming and React Server Components, hydration and its costs, islands architecture, edge rendering, and how to choose the right strategy for each page.
Where and when HTML gets generated is one of the biggest architectural decisions in a web app. It affects load speed, SEO, server cost, complexity and how fresh the data is.
The strategies
| Strategy | HTML generated | Good for | Watch out for |
|---|---|---|---|
| CSR — client-side rendering | In the browser, by JS, after load | Dashboards behind login, highly interactive apps | Blank page until JS loads; weaker SEO; big bundles |
| SSR — server-side rendering | On the server, per request | Personalised or fast-changing pages that need SEO | Server cost per request; TTFB depends on data fetching |
| SSG — static site generation | At build time | Docs, blogs, marketing, this site | Rebuild to update; build time grows with pages |
| ISR — incremental static regeneration | At build, then re-generated in the background after a revalidation period or on demand | Large catalogues, content that changes occasionally | Briefly stale data |
| Streaming SSR | On the server, sent in chunks as data resolves | Pages with slow and fast parts | Needs framework support |
CSR
Browser → GET / ← <div id="root"></div> + <script src="app.js">
Browser → GET app.js ← 400 KB of JS
(parse, execute, fetch data)
→ content finally visibleSSR
Browser → GET /product/42
Server: fetch data → render components to HTML
← full HTML (content visible immediately) + JS
Browser: download JS → hydrate → interactiveSSG
Build: for each page: fetch data → render HTML → write file → deploy to CDN
Browser → GET /docs/intro ← prebuilt HTML from the nearest CDN edge (very fast)Hydration
SSR and SSG pages arrive as HTML, but buttons don't work until JavaScript hydrates them: React re-runs the components in the browser, attaches event listeners, and reconciles with the existing DOM.
Costs of hydration:
- Uncanny valley: content is visible but not interactive.
- Double work: the server renders, then the client re-runs the same components.
- Bundle size: all component code ships to the browser, even for static parts.
- Hydration mismatches: if server and client render differently (dates,
Math.random(),windowchecks), React warns and may re-render.
Reducing hydration cost
React Server Components (RSC)
Components are split into two kinds:
- Server Components (the default in Next.js App Router): run only on the server (or at build). They can be
async, read databases and files directly, and their code never ships to the browser — they send a serialised result. - Client Components (
"use client"): ship to the browser and hydrate; they can use state, effects and event handlers.
// app/products/[id]/page.tsx — a Server Component
export default async function ProductPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const product = await db.product.findUnique({ where: { id } }); // direct DB access
return (
<article>
<h1>{product.name}</h1>
<Markdown source={product.description} /> {/* heavy library stays on the server */}
<AddToCartButton productId={id} /> {/* the only Client Component */}
</article>
);
}
// AddToCartButton.tsx
"use client";
export function AddToCartButton({ productId }: { productId: string }) {
const [pending, setPending] = useState(false);
return <button disabled={pending} onClick={…}>Add to cart</button>;
}Only the interactive leaves ship JavaScript.
Streaming with Suspense
Send the page shell immediately and stream slow sections as their data resolves:
<Layout>
<ProductDetails id={id} /> {/* fast */}
<Suspense fallback={<ReviewsSkeleton />}>
<Reviews id={id} /> {/* slow: streamed in later */}
</Suspense>
</Layout>Islands architecture
Frameworks like Astro render pages as static HTML and hydrate only the interactive "islands" (a carousel, a search box). Ideal for content-heavy sites. Qwik goes further with resumability: no hydration; event handlers load lazily on interaction.
Edge rendering
Run SSR on servers at CDN edge locations close to users (Cloudflare Workers, Vercel Edge, Deno Deploy) for low TTFB worldwide. Trade-off: edge runtimes are limited (no full Node APIs) and the database is usually still in one region — rendering at the edge but querying a distant DB can be slower than rendering near the DB. Pair edge rendering with edge caches or replicated data (Serverless and edge).
Choosing
| Page | Strategy |
|---|---|
| Marketing, docs, blog | SSG (rebuild or ISR on content change) |
| E-commerce product page | SSG/ISR for content + client-side or streamed price/stock |
| Search results, news feed | SSR (streaming) |
| Logged-in dashboard | CSR or SSR shell + client data fetching |
| Real-time collaborative editor | CSR (the app is the page) |
Modern frameworks (Next.js, Remix/React Router, Nuxt, SvelteKit, Astro) let you choose per route.
- CSR renders in the browser; SSR per request on the server; SSG at build time; ISR regenerates static pages in the background.
- Hydration makes server HTML interactive but costs JS download and double rendering.
- Server Components keep non-interactive code on the server; only Client Components ship JS.
- Streaming with Suspense sends the shell first and fills slow parts later.
- Islands and resumability minimise hydration; edge rendering cuts latency if data is close too.
- Pick the strategy per page based on freshness, personalisation, SEO and interactivity.
QWhat is hydration and why can it hurt performance?medium
Hydration is the client-side process where JavaScript re-runs the components that produced server-rendered HTML, attaches event handlers, and takes over the DOM. Until it finishes, the page looks ready but isn't interactive. It requires downloading and executing the code for every component on the page — even purely static ones — and repeats rendering work the server already did. Server Components, islands, partial or progressive hydration, and resumability all aim to reduce this cost.