SSR vs CSR
Comparing Server-Side Rendering (pre-built HTML from the server) against Client-Side Rendering (browser JS assembly)
Table of Contents
Structure Diagram
What is SSR vs CSR?
Comparing Server-Side Rendering (pre-built HTML from the server) against Client-Side Rendering (browser JS assembly). It is a core concept in Rendering & Frontend within Web Dev.
Core Principles
The distinction between SSR and CSR comes down to where HTML is assembled. In Server-Side Rendering (SSR), the server fetches data and generates complete HTML per request, allowing the browser to paint readable content immediately (fast FCP) and giving search crawlers full markup right away.
In Client-Side Rendering (CSR), the server sends a minimal HTML shell plus a JavaScript bundle; the browser downloads and runs JS, fetches API data, and constructs the DOM locally. Initial display is slower, but subsequent route transitions feel app-like and server CPU load stays low.
Practical Takeaways
- Adopt hybrid rendering: Modern frameworks like Next.js App Router let you render SEO-critical layouts and content via Server Components (SSR/SSG) while isolating highly interactive widgets (charts, editors, live filters) as Client Components.
- Watch TTFB and hydration: Slow database queries block SSR responses, inflating Time to First Byte (TTFB). Use Streaming SSR with Suspense so the shell arrives immediately while slower data sections stream in progressively.
- Prefer SSG/ISR for shared content: If every visitor sees the same page (blogs, docs, glossaries), pre-rendering at build time (SSG) beats per-request SSR in both latency and CDN cacheability.
Notable Examples
- SSR / SSG fit: E-commerce product catalogs, news portals, and public knowledge bases where SEO and fast first paint directly impact conversion.
- CSR fit: Authenticated analytics dashboards, collaborative canvas apps like Figma, and stateful admin consoles.
- React Server Components (RSC): Blends server-rendered zero-JS content with selective client interactivity in one unified tree.
Practical Code Snippet
Copy and drop straight into your project// Server Component (SSR / RSC): runs on server, ships 0KB fetch logicexport default async function ProductPage({ id }: { id: string }) { const product = await fetchProductFromDB(id); return <ProductView product={product} />;} // Client Component (CSR): hydrates in browser for live interactivity"use client";export function LikeButton({ initialCount }: { initialCount: number }) { const [count, setCount] = useState(initialCount); return <button onClick={() => setCount((c) => c + 1)}>♥ {count}</button>;}