Next.jsMedium

What is the difference between CSR, SSR, SSG, and ISR?

They differ in when and where HTML is produced: CSR builds it in the browser, SSR on the server per request, SSG once at build time, and ISR at build time with background regeneration. Modern Next.js mixes them inside one page.

The four strategies

  • CSR (Client-Side Rendering). The server sends a minimal shell and JavaScript renders the UI in the browser. Good for highly interactive, private dashboards. Weak for SEO and first paint.
  • SSR (Server-Side Rendering). HTML is generated on every request. Always fresh and personalized, but every request pays server time.
  • SSG (Static Site Generation). HTML is generated at next build and served from a CDN. Fastest and cheapest, but stale until the next build.
  • ISR (Incremental Static Regeneration). Static pages that regenerate after a time window or on demand, using stale-while-revalidate. New paths can be generated on first request.

How this maps to Next.js today

In the Pages Router the choice is per page: getServerSideProps (SSR), getStaticProps (SSG) and getStaticProps with revalidate (ISR).

In the App Router with Cache Components, the choice is per component, not per page:

  • Code with no request data or uncached I/O is prerendered into the static shell (SSG).
  • Code marked "use cache" with a cacheLife is cached and revalidated (ISR).
  • Code reading cookies(), headers(), searchParams or uncached data runs per request behind <Suspense> (SSR, streamed).
  • Client Components can still fetch in the browser (CSR).

This combination is Partial Prerendering (PPR): one route can be mostly static with a few dynamic holes.

Interview tip

Say what you would pick and why: a marketing page is static, a product page is cached with tag-based revalidation, a cart is request-time, and a live chart is client-rendered.

Code example

tsx
1// app/product/[id]/page.tsx - all four ideas in one route
2import { Suspense } from "react";
3import { cookies } from "next/headers";
4import { cacheLife } from "next/cache";
5import LivePrice from "./live-price"; // "use client" - CSR, polls in the browser
6
7async function ProductInfo({ id }: { id: string }) {
8 "use cache"; // ISR: cached, regenerated in the background
9 cacheLife("hours");
10 const p = await fetch(`https://api.example.com/products/${id}`).then((r) => r.json());
11 return <h1>{p.name}</h1>;
12}
13
14async function Cart() {
15 const session = (await cookies()).get("session")?.value; // SSR: per request
16 const cart = await fetch(`https://api.example.com/cart?s=${session}`).then((r) => r.json());
17 return <p>{cart.count} items in cart</p>;
18}
19
20export default async function Page({ params }: PageProps<"/product/[id]">) {
21 const { id } = await params;
22 return (
23 <>
24 <nav>Shop</nav> {/* SSG: part of the static shell */}
25 <ProductInfo id={id} />
26 <Suspense fallback={<p>Loading cart…</p>}>
27 <Cart />
28 </Suspense>
29 <LivePrice id={id} />
30 </>
31 );
32}

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 Next.js set.

Open in study app