Skip to solution
mediumFrontend

What is the difference between static and dynamic rendering in the Next.js App Router?

994 views
01

Understand the problem

Build-time HTML vs per-request rendering.

nextjsstaticdynamicrendering
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Static rendering produces HTML at build time (or revalidation) and serves it from cache; dynamic rendering runs per request. A route becomes dynamic when it uses dynamic functions (cookies, headers, searchParams) or uncached data; otherwise Next.js renders it statically.

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

A dynamic function forces per-request rendering
import { cookies } from 'next/headers';

export default async function Page() {
  const theme = (await cookies()).get('theme')?.value;  // → route is now DYNAMIC
  return <div data-theme={theme}></div>;
}

// Without cookies()/headers()/no-store, this route would be STATIC by default.
// Force it explicitly:  export const dynamic = 'force-static';
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 21 of 95 decoded in the Next.js track. One more won't hurt.

Back to track