Static and dynamic rendering

Intermediate · 11 min

Static rendering builds HTML once at build time, dynamic rendering per request. See what triggers each in Next.js 16 and how Cache Components changes it.

Before thisDynamic APIs: cookies, headers, and searchParamsThe four caches

Codevolution · 11 min

Static and dynamic rendering

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by CodevolutionReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Static rendering produces a page's HTML and RSC payload once, at build time, so any visitor is served finished output, usually from a CDN.
  • Dynamic rendering runs the component on the server for each request, which is needed for per-user or per-request data.
  • Without Cache Components, a route is dynamic if any part of it reads a request-time API like cookies() or headers(), so one read flips the whole route.
  • With Cache Components the question is asked per component: finished work, cached work, and Suspense fallbacks go into a static shell, and only request-time pieces stream.
  • next build prints a symbol for each route (static, partial prerender, dynamic), so check it after a change instead of guessing.

Two moments to render

A page has to be turned into HTML at some point. There are two moments to do it.

At build time. You run next build, Next.js renders the page once, and the output is stored. A visitor gets finished HTML. Nothing runs per visit, and the result can be served from a CDN. This is static rendering. The docs treat the terms as the same thing as prerendering.

At request time. The visitor arrives, the server runs your component, and the HTML is generated for that request. This is dynamic rendering, necessary when output depends on who is asking or what just changed.

An analogy: a bakery that bakes the morning bread before opening versus one that makes each sandwich to order. The first is faster for anything on the shelf. The second is the only option when the customer asks for a custom order.

What makes a page dynamic: the older model

A route is a candidate for static rendering by default. It becomes dynamic when it uses a request-time API: cookies(), headers(), searchParams, or draftMode().

I confirmed this on 16.4.6 with cacheComponents off. A page returning a constant built as ○ (static). A page that read cookies() built as ƒ (dynamic). A route with generateStaticParams and export const revalidate = 60 built as ● (SSG).

Every read taints the whole route. One cookie check in a layout and the whole route renders per request. That is why static-versus-dynamic was a route-level decision, and why people reached for route config like export const dynamic = 'force-dynamic' to force it.

What makes it dynamic now: the component model

With Cache Components, the decision moves down to individual components. A page is prerendered into a static shell:

  • Work that finishes at build time (imports, pure computation) goes in.
  • Cached results (use cache) go in.
  • Components that need the request sit behind <Suspense>; their fallback goes into the shell and the content streams in later.

So there is no all-or-nothing flip. A page with a static header, a cached product list, and a per-user greeting is one route with three different treatments. That is the idea behind partial prerendering, the next lesson. The route config options also go away: dynamic = 'force-dynamic' is simply removed, as the migration guide puts it, because uncached data and request-time APIs already run at request time.

The build enforces the discipline. If something needs the request and you gave it no boundary, next build fails with the blocking-route error covered earlier.

Check, don’t guess

The route table at the end of next build tells you what was decided:

Route (app)          Revalidate  Expire
┌ ○ /
├ ○ /api/items
├ ƒ /api/random
├ ◐ /ok                      1h      1d
└   /posts/[slug]
  ├ ◐ /posts/[slug]
  └ ○ /posts/a               1h      1d

That is real output (trimmed) from my 16.4.6 test project with Cache Components on: ○ static, ◐ partial prerender (static HTML with dynamic content streamed), ƒ dynamic, with revalidate and expire columns for cached content. Make a habit of reading it after you add a cookies() call or a use cache.

Development is different: in next dev pages are rendered on demand, so you do not see build-time behavior until you build.

Static does not mean frozen

A static page can still update. Cached content has a lifetime from cacheLife, and events can refresh it with a tag. The static shell is regenerated in the background. The ISR lesson covers that for routes with many pages.

What the video covers

Codevolution’s Next.js 15 tutorial is the static half of a two-part pair. By its chapters it covers server rendering strategies, how static rendering works, static rendering in development versus production, setting up static routes, analyzing the build output, serving the application, and prefetching with client-side navigation. The dynamic half is the linked runner-up. Both predate Cache Components, so they describe the route-level model that this lesson contrasts with the component-level one.

Where this fits

You know the two extremes. Next: partial prerendering, where one page gets both. For the React-level vocabulary, see CSR, SSR and static rendering concepts.

Check yourself

  1. 01What is the practical difference for a visitor between a static and a dynamic page?

    A static page is already built, so the server or CDN returns it immediately, while a dynamic page must run server code for each request before anything is sent, which costs time and server resources.

  2. 02Without Cache Components, what flips a route from static to dynamic?

    Reading a request-time API such as cookies(), headers(), or searchParams anywhere in the route, or uncached data discovered after such a read, makes the route render at request time.

  3. 03How does Cache Components change the static versus dynamic decision?

    It moves it from the whole route to individual components, so the page prerenders a static shell containing finished and cached work plus Suspense fallbacks, and only the request-dependent parts render at request time.

  4. 04How do you check what Next.js decided for each route?

    Run next build and read the route table, which marks routes as static, partial prerender, or dynamic, instead of inferring it from the code.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark