Next.js Draft Mode
Draft Mode allows you to preview content from your Headless CMS in real-time, even if the pages are normally statically generated (SSG).
How it Works
- Enable: You create a Route Handler that calls
draftMode().enable(). This sets a secure cookie in the browser. - Bypass Cache: When the cookie is present, Next.js bypasses the Full Route Cache and the Data Cache for
fetchrequests, ensuring the latest content is fetched from the CMS. - Disable: You can call
draftMode().disable()to clear the cookie and return to normal cached behavior.
Use Case
Content editors want to see how a blog post looks on the live site before hitting “Publish.” Draft Mode enables this without making the site dynamic for all users.