Nextjs Fundamentals · Caching & Revalidation

Static vs dynamic rendering

runtime APIs and rendering

Static vs dynamic rendering

Every route segment is either static — prerendered at build time — or dynamic — rendered on each request. What decides it is the data the segment reads.

Runtime APIs need information that only exists when a request arrives: cookies(), headers(), searchParams, and dynamic params. A component that reads them cannot finish during prerendering, so its work happens at request time:

async function UserGreeting() {
  const theme = (await cookies()).get('theme')?.value ?? 'light';
  return <p>Your theme: {theme}</p>;
}

Wrap such a component in <Suspense> so the shell still prerenders and the runtime read streams in. With Cache Components, reading cookies() no longer opts the whole route into dynamic rendering — the rest of the page stays static.

You can override the decision with the route segment config:

export const dynamic = 'force-static'; // prerender regardless
export const dynamic = 'force-dynamic'; // render every request

force-static is useful when a runtime API's value does not matter at build time; force-dynamic when the route must always be fresh. Leave it unset and Next.js infers the mode from the APIs the segment uses. Without a <Suspense> boundary, a runtime access surfaces a blocking-route insight in the dev overlay.

You are about to answer a short quiz on static vs dynamic rendering.

  1. A route segment that reads cookies() or headers() is rendered dynamically at request time.
  2. Setting export const dynamic = '___' forces a route to render on every request.
  3. With Cache Components, reading cookies() opts the entire route into dynamic rendering.
  4. Runtime APIs that require request information include cookies(), headers(), searchParams, and dynamic ___.
  5. Wrapping a runtime-reading component in Suspense lets the rest of the page stay static.
  6. export const dynamic = 'force-static' forces a route to be prerendered regardless of runtime APIs.