Skip to the solution
MediumFrontend7 min read

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

994 views

The problem

Question presented to candidate: "How does Next.js decide whether a route is static or dynamic, how can you tell which one you got, and what does each choice cost?"

What a strong answer should cover:

  • Static rendering happens at build time (or at revalidation); the result is served as a file to every user.
  • Dynamic rendering happens on each request; it is needed for per-request data.
  • Using a Request-time API such as cookies(), headers(), searchParams or connection(), or uncached data, makes a route dynamic.
  • The build output shows the result per route: β—‹ static, ● SSG with generateStaticParams, Ζ’ dynamic, and ◐ partial prerender with Cache Components.
  • The cost of dynamic is time to first byte, which streaming with loading.js or PPR reduces.

Clarifying questions expected:

  • "Does the content depend on who is asking?" β€” if not, it should be static.
  • "How fresh must it be?" β€” minutes of staleness allow static with revalidation (ISR).

Code / implementation expected: Yes β€” one static page, one ISR page and one dynamic page.

  • nextjs
  • static
  • dynamic
  • rendering

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

7 min read Β· 8 sections

Read the code

Static, ISR and dynamic pages side by side
// app/page.tsx  -> static (β—‹): no request data
export default function Home() {
  return <h1>Welcome</h1>;
}

// app/news/page.tsx  -> ISR (β—‹ with a lifetime)
export const revalidate = 30;
export default async function News() {
  const items = await getHeadlines();
  return <ul>{items.map((i) => <li key={i.id}>{i.title}</li>)}</ul>;
}

// app/account/page.tsx  -> dynamic (Ζ’): reads the request
import { cookies } from "next/headers";
export default async function Account() {
  const theme = (await cookies()).get("theme")?.value ?? "light";
  return <p>Your theme: {theme}</p>;
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 32 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

Caching defaults in Next 15 β€” what is no longer cached by default?

Continue