Fallback Pages and On-Demand Generation
You'll learn how to defer generating static pages for less-visited content until someone actually requests them, keeping build times fast while preserving static benefits.
The Problem with Pure Static Generation
Imagine you're building a documentation site with 10,000 pages. Building every single page at deploy time might take hours. But what if only 500 of those pages get visited regularly? You'd be wasting enormous build time generating pages that might never be seen.
How Fallback Pages Work
Fallback strategies let you cherry-pick which pages to pre-build and defer the rest until first request:
- At build time: Generate only your most critical pages (homepage, popular routes)
- On first visit: If a user requests a page that wasn't pre-generated, your server generates it on-demand
- After generation: The newly-generated page is cached as a static file for all future visitors
Think of it like a restaurant prep kitchen: you pre-make the popular dishes (salads, fries) but cook specialty items only when ordered. After the first order, you know the recipe and can serve it quickly next time.
The Best of Both Worlds
This approach combines:
- Fast builds: Only generate what you need upfront
- Static performance: Once generated, pages serve instantly from CDN
- No stale content: You can regenerate pages when data changes
- Scalability: Handle massive sites without massive build times
You typically return a fallback: true or fallback: 'blocking' option when defining which paths to pre-generate, allowing the system to handle missing routes gracefully rather than showing 404 errors.
Key Takeaway: Fallback pages let you defer static generation until first request, dramatically reducing build times for large sites while maintaining the speed and SEO benefits of static content after the initial generation.