Discover how to make your Next.js pages update only when they really need to!
Why Force-dynamic and force-static in NextJS? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine building a website where some pages need fresh data every time you visit, while others can stay the same for a long time.
You try to handle this by manually checking and updating each page's data yourself.
Manually managing when pages update or stay the same is confusing and slow.
You might forget to update some pages, or update too often, making your site slow or showing old info.
Next.js provides force-dynamic and force-static to tell the system exactly when to refresh a page or keep it cached.
This makes your site faster and always shows the right data without extra work.
if (needsUpdate) { fetchData(); renderPage(); } else { renderCachedPage(); }
export const dynamic = 'force-dynamic'; // or 'force-static';
You can easily control page updates, balancing speed and fresh content perfectly.
A news site shows breaking news pages with force-dynamic so they update instantly, while the about page uses force-static because it rarely changes.
Manually updating pages is error-prone and slow.
force-dynamic and force-static automate update control.
This leads to faster, fresher websites with less hassle.
Practice
force-dynamic directive do in Next.js?Solution
Step 1: Understand the purpose of
This directive tells Next.js to always fetch fresh data and update the page on every request.force-dynamicStep 2: Compare with other directives
Unlikeforce-static, which builds once,force-dynamicensures the page is never cached statically.Final Answer:
It makes the page update on every request. -> Option DQuick Check:
force-dynamic = update every request [OK]
- Confusing force-dynamic with force-static
- Thinking force-dynamic disables server rendering
- Assuming force-dynamic caches pages
Solution
Step 1: Recall the syntax for forcing static rendering
In Next.js app router, you useexport const dynamic = 'force-static';to make a page static.Step 2: Check other options
export const dynamic = 'force-dynamic'; forces dynamic, export const static = true; is invalid syntax, and export const revalidate = 0; controls ISR but not force-static.Final Answer:
export const dynamic = 'force-static'; -> Option AQuick Check:
force-static uses dynamic = 'force-static' [OK]
- Using force-dynamic instead of force-static
- Trying to use export const static = true
- Confusing revalidate with force-static
export const dynamic = 'force-static';
export default function Page() {
return {new Date().toISOString()}
;
}What will the page show when you refresh it multiple times?
Solution
Step 1: Understand force-static behavior
Withdynamic = 'force-static', the page is built once at build time and reused.Step 2: Analyze the date rendering
Thenew Date().toISOString()runs only once during build, so the date shown is fixed.Final Answer:
The date and time from when the page was first built, never changing. -> Option AQuick Check:
force-static = fixed build time content [OK]
- Expecting date to update on refresh
- Thinking force-static causes errors
- Confusing force-static with server-side rendering
export const dynamic = 'force-static';
What problem will this cause?
Solution
Step 1: Identify the directive effect
dynamic = 'force-static'makes the page static, so it does not update on each request.Step 2: Understand the impact on data freshness
The page will serve the cached static version, causing stale data to show.Final Answer:
The page will never update and show stale data. -> Option CQuick Check:
force-static = stale data if dynamic update needed [OK]
- Expecting syntax error from force-static
- Thinking page updates slowly instead of never
- Confusing infinite reload with static caching
force-static and caching?Solution
Step 1: Understand force-static with revalidate
force-staticforces static rendering, butrevalidate = 10enables Incremental Static Regeneration (ISR) with 10-second caching and on-demand revalidation.Step 2: Check other options
Options withforce-dynamicrender dynamically without ISR caching.revalidate = 0disables revalidation.Final Answer:
export const dynamic = 'force-static'; export const revalidate = 10; -> Option BQuick Check:
force-static + revalidate = ISR caching [OK]
- Using force-dynamic when ISR needed
- Setting revalidate to 0 disables revalidation
- Using force-static without revalidate for permanent static
