Course contentsShow
← Web Development
Lesson 1792 of 2,98233. Static Site Generation and JamstackFree lesson

Preview Modes for Draft Content

Implementing preview functionality to view unpublished content without triggering full site rebuilds.

Preview Modes for Draft Content

What you'll learn: How to view unpublished content changes instantly without waiting for lengthy site rebuilds.

The Problem with Pure Static Generation

With Static Site Generation, your content lives in pre-built HTML files. When an editor drafts a new blog post or updates a product description, they can't see it live until you rebuild the entire site—a process that might take minutes or even hours for large sites. That's frustrating when you just want to preview a single change.

How Preview Mode Works

Preview mode is a special bypass route. When activated (usually via a secure URL or token), your application switches from serving static files to fetching fresh data directly from your CMS or data source—just for that session. It's like having a "backstage pass" that lets you peek behind the curtain without rebuilding the stage.

The typical flow:

  1. Editor clicks "Preview" in the CMS
  2. CMS generates a signed preview URL with a secret token
  3. Your site validates the token and enables preview mode
  4. The page fetches draft content from the CMS in real-time
  5. Editor sees unpublished changes immediately
  6. Regular visitors still see the fast, static version

Key Implementation Elements

Preview mode requires:

  • Authentication: Secure tokens prevent unauthorized access to drafts
  • Dynamic fetching: Replace build-time data queries with request-time queries
  • Session management: Track which users have preview mode active
  • Clear exit mechanism: Let editors return to the public view

This approach combines SSG's speed for the public with real-time fetching for content authors—no full rebuild needed.

Key Takeaway: Preview mode lets content editors view draft changes instantly by temporarily switching from static files to real-time data fetching, without sacrificing the performance benefits of SSG for regular visitors.