Performance: Force-dynamic and force-static
This concept affects how Next.js handles server rendering and caching, impacting page load speed and responsiveness.
Jump into concepts and practice - no test required
export const dynamic = 'force-static'; export default function Page() { return <div>Static content</div>; }
export const dynamic = 'force-dynamic'; export default function Page() { return <div>Static content</div>; }
| Pattern | Server Load | Caching | Response Time | Verdict |
|---|---|---|---|---|
| force-dynamic | High (renders every request) | No caching | Slower (blocks rendering) | [X] Bad |
| force-static | Low (cached output) | Yes | Faster (quick HTML delivery) | [OK] Good |
force-dynamic directive do in Next.js?force-dynamicforce-static, which builds once, force-dynamic ensures the page is never cached statically.export const dynamic = 'force-static'; to make a page static.export const dynamic = 'force-static';
export default function Page() {
return {new Date().toISOString()}
;
}dynamic = 'force-static', the page is built once at build time and reused.new Date().toISOString() runs only once during build, so the date shown is fixed.export const dynamic = 'force-static';
dynamic = 'force-static' makes the page static, so it does not update on each request.force-static and caching?force-static forces static rendering, but revalidate = 10 enables Incremental Static Regeneration (ISR) with 10-second caching and on-demand revalidation.force-dynamic render dynamically without ISR caching. revalidate = 0 disables revalidation.