Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 72 ยท Rendering Strategies

SSG, SSR, ISR and Streaming Compared

Compare static generation, server rendering, incremental static regeneration and streaming in Next.js: when each fits, the tradeoffs and a decision table.

You will hear four abbreviations whenever people talk about how Next.js produces pages: SSG, SSR, ISR and streaming. They are not four products. They are four answers to the same question: when is the HTML for this page created, and how much of it is sent at once?

The older Pages Router tied each answer to a function (getStaticProps, getServerSideProps). The App Router has no such functions. The same ideas are still there, but they come out of what your components do, as you saw in Static vs Dynamic Rendering. This lesson gives each strategy a plain definition, compares them honestly, and ends with a way to choose.

The four strategies

Four answers to "when?"

SSG Render once at build time.
SSR Render on every request.
ISR Reuse a page, refresh it in the background.
Streaming Send the page in pieces.

You can mix them across routes, and even inside one route.

1 / 5

SSG: render at build time

With static site generation, the page is rendered during next build. The result is a plain HTML file (plus its data) that any server or CDN can hand out without running React. It is the fastest and cheapest option. The cost is freshness: if the data changes, visitors keep seeing the old page until you build again. A route is static when nothing in it needs a request, and dynamic segments become static when you list their values, which Static Generation and generateStaticParams explains.

SSR: render on every request

With server-side rendering, the server renders the route each time someone asks. The page can use the visitor's cookies, always shows current data and needs no build step to update. The cost is time and money: the browser waits for the server to finish, and the server does the work for every single visit. In the App Router this is "dynamic rendering".

ISR: static, but refreshed

Incremental static regeneration keeps a stored page and replaces it from time to time. When the stored copy is older than a limit you choose, the next visit still receives the old copy immediately, and a fresh render starts in the background. The visit after that gets the new page. This pattern is called stale-while-revalidate. You get static speed with data that is at most a little old, and you can also refresh a page on demand when something changes (see Revalidating Data).

In the classic model, you opt in with a time limit in seconds:

TSX
// app/news/page.tsx
export const revalidate = 60; // refresh the stored page at most once a minute

export default async function News() {
  const res = await fetch('https://api.example.com/headlines');
  const headlines: string[] = await res.json();
  return (
    <ul>
      {headlines.map((h) => (
        <li key={h}>{h}</li>
      ))}
    </ul>
  );
}

With Cache Components enabled, the same idea is written on the cached function or component, using 'use cache' and a profile such as cacheLife('minutes'). The idea is identical; only the spelling differs, and The use cache Directive and Cache Components covers it.

Streaming: send it in pieces

Streaming is not an alternative to the other three. It is about delivery. Instead of waiting for the slowest part of a page, the server sends the HTML that is ready now (the header, the title, the fast data) and sends the slow parts later, in the same response. React inserts them into the right place as they arrive. You mark the slow parts with Suspense boundaries or a loading.tsx file, which you will see in Streaming with Suspense. Streaming makes SSR feel faster, because the first byte no longer depends on the slowest query.

A decision diagram

flowchart TD
  A["Does the page differ per visitor?"] -->|"yes"| B["Render per request (SSR)"]
  A -->|"no"| C["How often does the data change?"]
  C -->|"rarely or never"| D["Build once (SSG)"]
  C -->|"every few minutes or hours"| E["Static plus revalidation (ISR)"]
  C -->|"constantly"| B
  B --> F{"Is some data slow?"}
  F -->|"yes"| G["Stream the slow parts with Suspense"]
  F -->|"no"| H["Plain SSR is fine"]

Choose by who the page is for and how fast its data goes out of date; stream whatever is slow.

Comparing them

SSG SSR ISR Streaming
HTML created At build time Each request At build, then refreshed Each request, in chunks
First byte Fastest Slowest Fastest Fast (shell first)
Data freshness As of the last build Always current A little stale, bounded Always current
Per-visitor content No Yes No Yes
Server work per visit None Full render Almost none Full render
Typical use Docs, blog posts Dashboards Product pages, news Pages with one slow widget

Two details deserve emphasis. First, mixing is normal: a store can have static marketing pages, ISR product pages, a dynamic cart and a streamed recommendations strip. Second, since Next.js 16 you can mix inside a single route: Partial Prerendering serves a static shell and streams the dynamic holes.

Seeing the timing difference

Real timings depend on your servers and network, so this live example uses a virtual clock and made-up numbers: a render costs 300 ms, the shell of the page (layout and fast parts) takes 50 ms, and a CDN adds 20 ms. Five visitors arrive at different seconds. For each strategy it prints the time to first byte and how old the data is. It is a model of the tradeoffs, not a benchmark.

Node.js Four strategies, five visitors

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Read the table the program prints. SSG is always quick but its data keeps aging. SSR is always fresh but every visitor pays 320 ms. ISR is as quick as SSG, and the visitor at second 61 gets a stale page while a refresh happens, so the visitor at second 62 sees data that is about one second old. Streaming finishes at the same moment as SSR but starts sending far earlier.

Choosing for real pages

The second example turns the decision diagram into code and applies it to six typical pages. Edit the descriptions to see how the answer changes.

Node.js A strategy picker

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Real projects have more inputs (traffic, cost, team habits), but the questions are the same ones you should ask about every route.

When unsure, start static and add dynamic behavior only where the page truly needs it. It is much easier to make a fast page more dynamic than to make a slow page fast.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which strategy renders a page once during the build and serves the same HTML to everyone?

    Static site generation renders at build time. The output is a file that a CDN can serve without running React.
  2. 2. In ISR, what does a visitor receive when the stored page is older than the revalidation limit?

    This is stale-while-revalidate: the visitor is not delayed, and the next visitor gets the refreshed page.
  3. 3. How is streaming different from the other three strategies?

    Streaming is about how a rendered page is sent. It is combined with SSR (or dynamic parts of a page) so the slowest query no longer decides the first byte.
  4. 4. A page shows the logged-in user's order history. Which approach fits?

    Personal content cannot be shared between visitors, so it has to be rendered per request (and slow parts can be streamed).

Summary

  • SSG renders at build time, SSR on every request, ISR serves a stored page and refreshes it in the background, and streaming sends a page in pieces.
  • In the App Router you do not call a function for each strategy: your code (request-time APIs, caching, Suspense) leads Next.js to the right one.
  • SSG and ISR give the fastest first byte; SSR gives the freshest and the only personalized output; streaming makes slow SSR feel quick.
  • Choose by two questions: does the page differ per visitor, and how fast does its data age? Then stream whatever is slow.
  • Strategies mix freely across routes, and Partial Prerendering mixes them inside one route.

Next: Static Generation and generateStaticParams