Static, Dynamic and Streaming Rendering
A version-qualified path through the Next.js App Router: server components, client boundaries, data fetching, caching layers, streaming, error handling, proxy, images, performance, testing and deployment, with the Next.js 15 and 16 behavior changes called out where they matter.
What you will be able to do
#- Decide per route whether it should prerender, render per request, or stream.
- Use generateStaticParams and dynamicParams to control build-time generation.
- Apply route segment config correctly and describe its changed role under Cache Components.
Overview
#Three rendering outcomes
At build time Next.js prerenders routes whose output does not depend on request-time data: the HTML and the RSC payload are generated once and served statically. Routes that read dynamic APIs (cookies, headers, searchParams) or uncached data render per request. Any route can stream: the shell ships first and Suspense boundaries fill in as their data resolves. The build log is the source of truth: it marks each route with a symbol for static, dynamic, or streaming behavior, and reading it after every change should be a habit.
generateStaticParams
For dynamic segments, generateStaticParams enumerates which parameter values to prerender at build time:
// app/blog/[slug]/page.tsx
export async function generateStaticParams() {
const posts = await getPostSlugs();
return posts.map((slug) => ({ slug }));
}
dynamicParams controls the rest: true (default) renders unknown params on demand, false returns 404 for anything not prerendered. Nested dynamic segments compose: a child segment's generateStaticParams runs once per parent-generated param set.
Route segment config and its new role
The previous model used segment exports as mode switches: dynamic = 'force-static' | 'force-dynamic' | 'error', revalidate = n, fetchCache. Under Cache Components these switches lose their primary role: one route combines prerendered UI, cached sections and request-time sections, and the lever becomes where you put use cache and Suspense. Next.js 16.4 adds ensureStatic (with Cache Components enabled) for routes that must avoid request-time server rendering entirely, for example to guarantee predictable compute costs. Know both vocabularies: interviews and older codebases use the segment configs, current docs describe Cache Components.
Choosing per route
Marketing pages, docs and product detail pages with stable data: prerender (with generateStaticParams where segments exist). Dashboards with per-user data: dynamic shell or prerendered shell plus Suspense-isolated user data. Search results: streaming with the query read inside a Suspense boundary. The decision inputs are data visibility (same for everyone?), staleness tolerance, and personalization surface.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Predict
app/blog/[slug]/page.tsx has generateStaticParams returning [{ slug: 'a' }, { slug: 'b' }] and no dynamicParams export. What happens for /blog/a, /blog/b and /blog/c at request time after build?
Exercise 2Explain
Explain the difference between a prerendered page with revalidate = 60 and a page rendered per request with an internal 60-second cache. Who notices the difference, and when?
Reveal the reference answer
reference.textWith revalidate = 60 the route's rendered output is stored and served without executing the page for most requests; the server pays rendering cost at most once per minute, and response latency is cache-read speed for everyone. With per-request rendering plus a 60-second data cache, every request executes the component tree (cheap if data is cached, but layout, serialization and streaming still run), so latency includes render work even when the data is reused. Users notice during traffic spikes: the first approach holds latency flat; the second degrades with concurrency. The build also differs: the first produces prerendered artifacts, the second marks the route dynamic.Authored expected output: Rendered-output caching versus data-only caching, with latency and cost consequences.
Full route caching and data caching solve different halves of the cost equation.
Exercise 3Implement
Make app/docs/[...path]/page.tsx prerender every doc page at build time from a getDocPaths() source, and 404 any path not in the source.
starter.tsx// app/docs/[...path]/page.tsx // TODO: generateStaticParams from getDocPaths, dynamicParams false, page renders the docReveal the reference answer
reference.tsximport { notFound } from 'next/navigation'; export const dynamicParams = false; export async function generateStaticParams() { const paths = await getDocPaths(); return paths.map((p) => ({ path: p.split('/') })); } export default async function Page({ params, }: { params: Promise<{ path: string[] }>; }) { const { path } = await params; const doc = await getDoc(path.join('/')); if (!doc) notFound(); return <article>{doc.body}</article>; } // Catch-all params are arrays, so generateStaticParams returns the split path for each doc.Authored expected output: Every known doc is a static page; unknown paths return 404 without a server render attempt.
dynamicParams: false converts unknown params into not-found instead of on-demand renders.
Exercise 4Debug
A team expects their docs site to be fully static, but the build output marks every route dynamic. One line is the culprit; find it. import { cookies } from 'next/headers'; export default async function Layout({ children }) { const theme = (await cookies()).get('theme'); return <body data-theme={theme?.value ?? 'light'}>{children}</body>; }
starter.tsximport { cookies } from 'next/headers'; export default async function Layout({ children }) { const theme = (await cookies()).get('theme'); return <body data-theme={theme?.value ?? 'light'}>{children}</body>; }Reveal the reference answer
reference.tsxReading cookies() in the root layout makes every route below it dynamic, because the layout output depends on request state. Fixes: move the theme read into a small client component that reads document.cookie or a theme provider, or read the cookie inside a Suspense-isolated child so the shell stays prerenderable (the Cache Components pattern). The root layout is the worst place for request-time reads because it poisons the whole tree.Authored expected output: Routes prerender again once the cookie read leaves the root layout.
Dynamic APIs anywhere in a segment's tree opt that segment into request-time rendering.
Exercise 5Test
Write a pure function classifyRoute(opts: { hasDynamicApi: boolean; hasUncachedFetch: boolean; hasSuspenseIsolation: boolean }) returning 'static' when neither dynamic API nor uncached fetch is present, 'dynamic' when dynamic API or uncached fetch exists outside Suspense, and 'shell-plus-stream' when request-time access exists but hasSuspenseIsolation is true. Assert on three combinations covering each output.
starter.tsexport function classifyRoute(opts: { hasDynamicApi: boolean; hasUncachedFetch: boolean; hasSuspenseIsolation: boolean; }): 'static' | 'dynamic' | 'shell-plus-stream' { // TODO }Reveal the reference answer
reference.tsexport function classifyRoute(opts: { hasDynamicApi: boolean; hasUncachedFetch: boolean; hasSuspenseIsolation: boolean; }): 'static' | 'dynamic' | 'shell-plus-stream' { const requestTime = opts.hasDynamicApi || opts.hasUncachedFetch; if (!requestTime) return 'static'; return opts.hasSuspenseIsolation ? 'shell-plus-stream' : 'dynamic'; } // This encodes the prerender rule: request-time access is allowed only inside a boundary.Authored expected output: All three assertions pass.
The classifier mirrors how the build decides a route's rendering outcome.
Exercise 6Interview
An interviewer asks: how do you decide the rendering strategy for a new route? Give your checklist and one example where the answer changed after launch.
Reveal the reference answer
reference.textChecklist: (1) visibility: is the output identical for every user? (2) staleness: how old may the data be? (3) personalization: which parts actually depend on the request? (4) traffic shape: spiky launch traffic favors prerender plus revalidate. Then map: same-for-everyone plus tolerant staleness gives prerender with generateStaticParams and tag-based invalidation; per-user sections give a prerendered shell with Suspense-isolated request-time reads; truly live gives dynamic rendering with a loading boundary. Example of a change: a pricing page launched as fully dynamic because it read an experiment cookie in the layout; after moving the experiment branch into a client component the page prerendered, cutting server render cost to zero for the highest-traffic marketing route. State the honest verification: the build output symbols and server timing, not vibes.Authored expected output: Four-question checklist, mapping to strategies, one concrete reversal with evidence.
Strategy questions test whether you treat rendering mode as a cost decision.
Common misconceptions
#- Static means the page never changes. Prerendered output can revalidate on a timer or be invalidated on demand; static describes when it is generated, not immutability.
- dynamic = 'force-dynamic' is required for pages with fetch. Since Next.js 15 uncached fetch already renders dynamically; the segment config is for explicit mode control.
- generateStaticParams makes the route dynamic. It does the opposite: it enumerates build-time prerendering for dynamic segments.
- Streaming requires Cache Components. Streaming with Suspense and loading.tsx works in all App Router versions; Cache Components formalizes shell-first prerendering.
Follow-up practice
#- nextjs-loading-streaming
- nextjs-cache-components
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.