Skip to the page

Caching in Next.js 16 · senior

Cache Components and Partial Prerendering: the static shell

With Cache Components, Next.js prerenders a static shell for every route from everything that can finish at build time (static code, "use cache" results, Suspense fallbacks) and streams the request-time parts into the same response; you must put runtime data behind Suspense or cache it.

The notes

What you must know

  • Enable with cacheComponents: true and partialPrefetching: true (set the second explicitly; leaving it unset logs a warning). Both become the only behaviour in Next 17.
  • In the shell: synchronous/predictable work (imports, pure computation, sync file reads), "use cache" output (unless its lifetime is too short), and Suspense fallbacks.
  • Runtime APIs (cookies(), headers(), searchParams, params not covered by generateStaticParams) and uncached async data must be inside <Suspense>, or the dev overlay shows a "blocking-route" insight and the build validation fails.
  • Math.random(), Date.now(), crypto.randomUUID(): call await connection() first (inside Suspense) for per-request values, or cache them with "use cache".
  • Push runtime access down: do not await params in a layout; pass the promise into a child inside Suspense so the rest of the layout stays in the shell.
  • Reading cookies() inside a Suspense boundary no longer makes the whole route dynamic (it did in the previous model).
  • 16.4 export const ensureStatic = "shell" | "prefetch" | "navigation" fails the build if dynamic content sneaks into the shell, the prefetch, or any navigation; it can be set on a layout to cover its pages.
  • Short lifetimes become dynamic holes: revalidate: 0 or expire under 5 minutes, or stale under 30 s, are excluded from prerenders; stale from 30 s to under 5 min is prerendered but excluded from the App Shell. Of the presets only seconds is excluded.

The red pen

Common traps: mistake → fix

  • Mistake: "One cookies() call makes the whole page dynamic"

    Fix: only its Suspense boundary is request-time.

  • Mistake: "Wrap everything in 'use cache' to fix build errors"

    Fix: per-request data needs Suspense, not caching.

  • Mistake: "<Suspense> makes a component dynamic"

    Fix: it only provides a fallback; synchronous children still prerender.

Easy to hard

Questions interviewers ask, easy to hard

  1. A homepage has a static hero, a static pricing table and a live "recently purchased" feed (800 ms). Build it so LCP is not hurt.
  2. Why must the feed be inside <Suspense>?
  3. Awaiting params in a layout killed the shell. Fix it.
  4. How do you guarantee a marketing route never becomes dynamic?
  5. Turning on Cache Components made the build fail. How do you work through the errors?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview