Careeroza
Static vs Dynamic Rendering
Two Kinds of Routes
| Static | Dynamic | |
|---|---|---|
| Rendered | At build time (or on revalidation) | On every request |
| Build output symbol | ○ or ● | ƒ |
| Speed | Fastest: served from cache/CDN | Depends on your data sources |
| Good for | Home, category pages, blog, product pages | Cart, account, search, personalised pages |
What Makes a Route Dynamic
- Calling dynamic APIs:
cookies(),headers(),connection(),draftMode(). - Reading
searchParamsin a page. - A
fetchwithcache: 'no-store'ornext: { revalidate: 0 }. - Route segment config:
export const dynamic = 'force-dynamic'.
// app/cart/page.tsx
import { cookies } from 'next/headers';
export default async function CartPage() {
const cartId = (await cookies()).get('cartId')?.value; // makes the route dynamic
// ...
}Route Segment Config
// in any page.tsx or layout.tsx
export const dynamic = 'force-static'; // or 'force-dynamic' | 'auto' (default) | 'error'
export const revalidate = 3600; // seconds; ISR for the whole route
export const runtime = 'nodejs'; // or 'edge'