What is Draft Mode in Next.js and when would you use it?
Short answer
Draft Mode lets content editors preview unpublished changes from a content management system before they go live, by temporarily bypassing the normal static caching so the page always shows the latest draft content instead of the cached published version.
Advertisement
AModel answer
Draft Mode lets content editors preview unpublished changes from a content management system before they go live, by temporarily bypassing the normal static caching so the page always shows the latest draft content instead of the cached published version.
// app/api/draft/route.js
import { draftMode } from 'next/headers';
export async function GET() {
const draft = await draftMode();
draft.enable();
return new Response('Draft mode enabled');
}Real-world example
A magazine website lets its editors click a preview button in their content management system, which enables Draft Mode and shows them exactly how an unpublished article will look before it goes live to readers.
Likely follow-ups
- How does Draft Mode work together with a headless CMS?
- How do you disable Draft Mode once you are done previewing?
Related topics