Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Using force-dynamic and force-static in Next.js
📖 Scenario: You are building a simple Next.js page that shows a greeting message. You want to control whether the page is rendered dynamically on each request or statically at build time.
🎯 Goal: Create a Next.js page that uses export const dynamic = 'force-dynamic' to make the page render dynamically, then change it to export const dynamic = 'force-static' to make it render statically.
📋 What You'll Learn
Create a Next.js page component named GreetingPage that returns a simple greeting message inside a <main> element.
Add an export named dynamic with the value 'force-dynamic' to make the page render dynamically.
Change the dynamic export value to 'force-static' to make the page render statically.
Ensure the page component and export are correctly structured for Next.js 14+ App Router.
💡 Why This Matters
🌍 Real World
Controlling whether a Next.js page renders dynamically or statically helps optimize performance and user experience depending on the content freshness needed.
💼 Career
Understanding force-dynamic and force-static exports is important for Next.js developers to build efficient, scalable web applications with proper rendering strategies.
Progress0 / 4 steps
1
Create the Next.js page component
Create a React functional component named GreetingPage that returns a <main> element with the text Hello, welcome to Next.js!.
NextJS
Hint
Use a function named GreetingPage that returns JSX with a <main> tag and the greeting text.
2
Add force-dynamic export
Add an export named dynamic with the exact value 'force-dynamic' below the GreetingPage component to make the page render dynamically.
NextJS
Hint
Write export const dynamic = 'force-dynamic'; exactly as shown.
3
Change to force-static export
Change the existing export named dynamic to have the exact value 'force-static' instead of 'force-dynamic'.
NextJS
Hint
Replace 'force-dynamic' with 'force-static' in the export statement.
4
Complete the Next.js page with static rendering
Ensure the page component GreetingPage and the export dynamic = 'force-static' are correctly structured and exported for Next.js 14+ App Router.
NextJS
Hint
Make sure the component and export statements are present and correct.
Practice
(1/5)
1. What does the force-dynamic directive do in Next.js?
easy
A. It caches the page for offline use.
B. It makes the page build once and never update.
C. It disables server-side rendering.
D. It makes the page update on every request.
Solution
Step 1: Understand the purpose of force-dynamic
This directive tells Next.js to always fetch fresh data and update the page on every request.
Step 2: Compare with other directives
Unlike force-static, which builds once, force-dynamic ensures the page is never cached statically.
Final Answer:
It makes the page update on every request. -> Option D
Quick Check:
force-dynamic = update every request [OK]
Hint: force-dynamic means fresh page every time [OK]
Common Mistakes:
Confusing force-dynamic with force-static
Thinking force-dynamic disables server rendering
Assuming force-dynamic caches pages
2. Which is the correct way to force a page to be static in Next.js using the new app router?
easy
A. export const dynamic = 'force-static';
B. export const static = true;
C. export const dynamic = 'force-dynamic';
D. export const revalidate = 0;
Solution
Step 1: Recall the syntax for forcing static rendering
In Next.js app router, you use export 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 A
Quick Check:
force-static uses dynamic = 'force-static' [OK]
Hint: Use dynamic = 'force-static' to make static pages [OK]
What will the page show when you refresh it multiple times?
medium
A. The date and time from when the page was first built, never changing.
B. The current date and time updated on every refresh.
C. An error because dynamic cannot be force-static.
D. A blank page because the date is not static.
Solution
Step 1: Understand force-static behavior
With dynamic = 'force-static', the page is built once at build time and reused.
Step 2: Analyze the date rendering
The new 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 A
Quick Check:
force-static = fixed build time content [OK]
Hint: force-static shows build time data, not live updates [OK]
Common Mistakes:
Expecting date to update on refresh
Thinking force-static causes errors
Confusing force-static with server-side rendering
4. You want a Next.js page to update on every request but accidentally wrote:
export const dynamic = 'force-static';
What problem will this cause?
medium
A. The page will reload infinitely causing a crash.
B. The page will throw a syntax error and not load.
C. The page will never update and show stale data.
D. The page will update but with a delay.
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 C
Quick Check:
force-static = stale data if dynamic update needed [OK]
Hint: force-static stops updates, use force-dynamic for fresh data [OK]
Common Mistakes:
Expecting syntax error from force-static
Thinking page updates slowly instead of never
Confusing infinite reload with static caching
5. You have a Next.js page that fetches user data and you want it statically rendered but revalidated every 10 seconds on demand to keep data fresh, also improving performance by caching for 10 seconds. Which setup correctly combines force-static and caching?