Implement ISR with On-Demand Revalidation
Intermediatev1.0.0
Master Incremental Static Regeneration on Vercel — time-based and on-demand revalidation, stale-while-revalidate patterns, and cache management for dynamic content.
Content
Overview
Incremental Static Regeneration (ISR) combines the performance of static pages with the freshness of dynamic content. Pages are statically generated at build time, then revalidated in the background — either on a time interval or on-demand via webhook.
Why This Matters
- -Static performance — pages served from CDN edge in <50ms
- -Fresh content — pages update without full rebuild
- -Cost efficiency — reduces serverless function invocations
- -Scalability — handles traffic spikes without compute scaling
How It Works
Step 1: Time-Based Revalidation
Step 2: On-Demand Revalidation via API Route
Step 3: Tag-Based Cache Management
Step 4: Webhook Integration (CMS)
Best Practices
- -Use tag-based revalidation for granular cache control
- -Set a fallback revalidate time even with on-demand (safety net)
- -Protect revalidation endpoints with a shared secret
- -Revalidate listing pages when individual items change
- -Use
generateStaticParamsfor known paths at build time - -Monitor cache hit rates with Vercel Analytics
Common Mistakes
- -Setting revalidate too low (defeats the purpose of caching)
- -Not revalidating listing pages when detail pages change
- -Exposing revalidation endpoints without authentication
- -Using SSR when ISR with on-demand revalidation would suffice
- -Not handling 404 cases with
notFound()for deleted content
FAQ
Discussion
Loading comments...