0
0
NextJSframework~8 mins

Force-dynamic and force-static in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Force-dynamic and force-static
MEDIUM IMPACT
This concept affects how Next.js handles server rendering and caching, impacting page load speed and responsiveness.
Rendering a page that rarely changes and benefits from caching
NextJS
export const dynamic = 'force-static';

export default function Page() {
  return <div>Static content</div>;
}
Enables caching of the page output, reducing server work and speeding up response time.
📈 Performance GainReduces server response time by 50-80%; improves LCP by caching HTML
Rendering a page that rarely changes and benefits from caching
NextJS
export const dynamic = 'force-dynamic';

export default function Page() {
  return <div>Static content</div>;
}
Forces server to render on every request, disabling caching and increasing server load and response time.
📉 Performance CostBlocks rendering for extra 100-200ms per request; increases server CPU usage
Performance Comparison
PatternServer LoadCachingResponse TimeVerdict
force-dynamicHigh (renders every request)No cachingSlower (blocks rendering)[X] Bad
force-staticLow (cached output)YesFaster (quick HTML delivery)[OK] Good
Rendering Pipeline
Force-dynamic disables caching causing Next.js to render the page on every request, increasing server processing and delaying HTML delivery. Force-static enables caching, so the server can quickly serve pre-rendered HTML without reprocessing.
Server Rendering
Network Transfer
Browser Rendering
⚠️ BottleneckServer Rendering
Core Web Vital Affected
LCP
This concept affects how Next.js handles server rendering and caching, impacting page load speed and responsiveness.
Optimization Tips
1Use force-static to enable caching and faster page loads for stable content.
2Avoid force-dynamic unless you need fresh data on every request.
3Check server response times in DevTools Network tab to verify caching behavior.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance impact of using force-dynamic in Next.js?
AIt disables caching and causes the server to render on every request.
BIt enables aggressive caching for faster loads.
CIt reduces server CPU usage by caching HTML.
DIt improves client-side rendering speed.
DevTools: Network
How to check: Open DevTools, go to Network tab, reload the page, and check the timing of the HTML document request.
What to look for: Look for longer server response times indicating force-dynamic; shorter times with cache headers indicate force-static.