Skip to content

Lesson 2 of 27Foundations

Rendering Strategies

Tell CSR, SSR, SSG, ISR, streaming and partial prerendering apart, and pick the right one for each page.

15 min read0/4 questions

"What is the difference between SSR, SSG and ISR?" is one of the most common Next.js interview questions, and the answer decides real things: how fast a page loads, how fresh its data is, and how much your servers cost. The trick is that every strategy is an answer to two questions: where does the HTML get made, and when?

The two questions

  • Where: in the browser (client) or on a server.
  • When: at build time, at request time, or at build time and then refreshed later.

Every acronym below is a combination of those answers. Keep the waiting user in mind: the time until the first byte arrives (TTFB, time to first byte) and the time until real content is on screen.

Run this simulation. Each strategy is a list of steps with rough costs in milliseconds.

TypeScriptwhen-does-content-appear.ts
type Step = [label: string, ms: number]; const strategies: Record<string, Step[]> = { CSR: [["CDN sends empty HTML", 40], ["download + run JS", 300], ["fetch data in useEffect", 250]], SSR: [["server fetches data", 250], ["server renders HTML", 60], ["HTML arrives", 40]], SSG: [["CDN sends prebuilt HTML", 40]],}; for (const [name, steps] of Object.entries(strategies)) { const total = steps.reduce((sum, [, ms]) => sum + ms, 0); console.log(`${name.padEnd(4)} content visible after ~${total}ms (${steps.map(([l]) => l).join(" → ")})`);}
Output
Press Run (⌘ Enter) to see what happens.

SSG wins on speed, but its HTML was made at build time. That is fine for a blog post and wrong for a shopping cart. The rest of this lesson is about that trade-off.

The four classic strategies

Client-side rendering. The server sends a shell and a bundle; the browser renders and fetches. Fast to host (static files), slow to first content, weak for SEO. In Next.js you get this for parts of a page by fetching inside a Client Component with useEffect or a library like SWR or TanStack Query.

Client-side rendering
BrowserCDNAPIGET /dashboardempty HTML + JSrun React, show spinnerfetch /api/statsJSON

GET /dashboard

1/5
Quick check
A product page uses ISR with a 60 second revalidate. It was built 5 minutes ago. What does the next visitor get?
Need a nudge? A hint rules out a wrong answer.

Here is the ISR rule as code. The visitor who triggers the rebuild still gets the old version.

TypeScriptisr.ts
let version = 1;let builtAt = 0;const revalidate = 60; for (const t of [30, 90, 100, 170]) { console.log(`t=${t}s served v${version}`); if (t - builtAt >= revalidate) { version++; builtAt = t; console.log(` rebuilt in background → v${version}`); }}
Output
Press Run (⌘ Enter) to see what happens.
Predict the outputTypeScript

What does this print?

let version = 1;
let builtAt = 0;
const revalidate = 60;
for (const t of [30, 90, 100]) {
console.log(version);
if (t - builtAt >= revalidate) { version++; builtAt = t; }
}
Need a nudge? Hints walk you through it.

Streaming: stop waiting for the slowest query

SSR has a weakness: one slow query holds back the whole page. Streaming fixes it. The server sends the HTML it can render right away, with placeholders, and keeps the connection open. As each slow part finishes, React sends it down the same response and swaps it into place.

In React the placeholder is a <Suspense> boundary: a component that shows a fallback while anything inside it is still loading. You can feel the effect in the browser with React 19's use() hook, which suspends until a Promise resolves.

Reactstreaming-feel.tsx
import { Suspense, use } from "react"; const slowReviews = new Promise<string[]>((resolve) => setTimeout(() => resolve(["Great grinder", "Quiet and fast"]), 1500),); function Reviews() { const reviews = use(slowReviews); return <ul>{reviews.map((r) => <li key={r}>{r}</li>)}</ul>;} export default function App() { return ( <main style={{ fontFamily: "system-ui" }}> <h2>Coffee grinder</h2> <p>$129. In stock.</p> <Suspense fallback={<p>Loading reviews...</p>}> <Reviews /> </Suspense> </main> );}

The title and price show instantly; reviews fill in later. In Next.js the same thing happens on the server, over a single HTTP response.

Streaming with Suspense
BrowserServerReviews APIGET /product/42fetch reviewsheader, price, fallbackreviewsreviews HTML chunk

GET /product/42

1/5

Partial prerendering and Cache Components (Next.js 16)

Most real pages are mixed: the layout and product details are the same for everyone, the cart badge depends on a cookie. Next.js 16 stops asking you to pick one mode per page. With Cache Components turned on (cacheComponents: true in next.config.ts, which new create-next-app projects enable by default), every page follows one model called Partial Prerendering (PPR):

  1. At build time, Next.js renders the page and keeps everything it can: plain markup, and anything marked with the "use cache" directive.
  2. Anything that needs the request (cookies, headers, search params, uncached data) must sit inside a <Suspense> boundary. Its fallback goes into the prerendered HTML.
  3. The result is a static shell served instantly from a CDN, with holes that stream in at request time.
Put it in order5 steps

Put the life of a partially prerendered page in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

If a component reads request data without a Suspense boundary, next build stops with an error that offers three fixes: stream it (wrap it in Suspense), cache it ("use cache"), or explicitly allow the route to block. The build output marks each route: ○ fully static, ◐ partial prerender (shell plus streamed holes), ƒ rendered entirely on demand. You will write use cache yourself in the data fetching lesson.

What about the previous model?

Apps without cacheComponents use the model from Next.js 13 to 15: each route is either fully static or fully dynamic. A route becomes dynamic as soon as anything in it reads cookies(), headers() or searchParams, and time-based ISR is configured with export const revalidate = 60 in the page file. You will see this in many existing codebases. The mental model (static where possible, stream what is not) carries over.

Choosing a strategy

StrategyHTML madeFreshnessSpeedTypical page
CSRIn the browserLiveSlow first paintHighly interactive widgets behind login
SSRServer, every requestLiveWaits on dataAccount pages, search results
SSGBuild timeUntil next deployFastestDocs, marketing, blog posts
ISRBuild, then background refreshBounded stalenessFastProduct catalogs, news listings
StreamingServer, in chunksLiveFast first bytePages with one slow section
PPRStatic shell + streamed holesMixed per componentFast shell, live holesMost pages in a Next.js 16 app
Match the pairs0/4 matched

Match each page to the strategy that fits best.

Choose an item, then its match on the other side.
ChallengeEasy

Static, partial, or dynamic?

With Cache Components on, next build prints a symbol next to every route: ○ static, ◐ partial prerender, ƒ dynamic. Write classifyRoute(parts) that predicts it.

Each part of the page is one of:

  • "static": plain JSX or data known at build time
  • "cached": a component or function with "use cache" and a normal lifetime
  • "suspended": runtime data (cookies, headers, uncached fetch) inside a <Suspense> boundary
  • "blocking": runtime data with no <Suspense> boundary above it

Return "dynamic" if any part is blocking, "partial" if any part is suspended, otherwise "static".

["static", "cached"]               → "static"
["static", "suspended"]            → "partial"
["cached", "suspended", "blocking"] → "dynamic"
TypeScript
type Part = "static" | "cached" | "suspended" | "blocking"; function classifyRoute(parts: Part[]): "static" | "partial" | "dynamic" { // Check the strongest condition first. return "static";}
ChallengeMedium

Simulate stale-while-revalidate

Incremental Static Regeneration serves the cached page and refreshes it in the background. Simulate it.

Version 1 of a page is built at time 0. Requests arrive at the times in times (seconds, ascending). For each request:

  1. Serve the current version.
  2. If time - builtAt >= revalidate, the page is stale: a background rebuild finishes right after the response, so the version goes up by one and builtAt becomes this request's time.

Return the version each request was served.

revalidate = 60, times = [10, 70, 75, 200]  →  [1, 1, 2, 2]

The request at 70 still gets version 1 (stale), but triggers version 2 for everyone after it.

TypeScript
function servedVersions(revalidate: number, times: number[]): number[] { // Track the current version and when it was built. return [];}
Key terms
SSR
Server-side rendering: HTML is rendered on the server for every request. Fresh, but each visitor waits for the data.
SSG
Static site generation: HTML is rendered once at build time and served from a CDN.
ISR
Incremental Static Regeneration: static pages that are rebuilt in the background after a revalidate time or on demand.
stale-while-revalidate
Serve the cached (stale) version immediately and refresh it in the background for the next visitor.
streaming
Sending HTML in chunks over one response, so fast parts appear while slow parts are still rendering behind Suspense fallbacks.
partial prerendering (PPR)
Next.js 16's default with Cache Components: a prerendered static shell with request-time parts streamed into Suspense holes.