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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Enable with
cacheComponents: trueandpartialPrefetching: 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,paramsnot covered bygenerateStaticParams) 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(): callawait connection()first (inside Suspense) for per-request values, or cache them with"use cache".- Push runtime access down: do not
await paramsin 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: 0orexpireunder 5 minutes, orstaleunder 30 s, are excluded from prerenders;stalefrom 30 s to under 5 min is prerendered but excluded from the App Shell. Of the presets onlysecondsis 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
- 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.
- Why must the feed be inside
<Suspense>? - Awaiting
paramsin a layout killed the shell. Fix it. - How do you guarantee a marketing route never becomes dynamic?
- 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 voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.