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