Revalidation
Master Next.js revalidation — time-based, on-demand, and tag-based strategies for keeping cached content fresh without sacrificing performance.
Last reviewed: January 2025
🔍 What Is It?
Revalidation is the mechanism for invalidating and refreshing cached content in Next.js. Three strategies:
- Time-based —
next: { revalidate: 3600 }— refresh after N seconds (ISR) - On-demand path —
revalidatePath('/products/slug')— invalidate a specific URL - On-demand tag —
revalidateTag('products')— invalidate all content with a tag
Revalidation uses stale-while-revalidate: serve the cached version immediately, rebuild in the background, serve fresh version to subsequent requests.
🎯 Why Do We Need It?
Without revalidation, you face a binary choice:
- →SSG — fast but stale until next full deploy
- →SSR — always fresh but slow and expensive
Revalidation gives you a third option: static performance + controlled freshness. You decide exactly when content updates, either by time or by event (CMS publish, price change, stock update).
🏗️ What Happens in Real Projects?
Revalidation strategy by content type:
| Content Type | Strategy | Revalidate |
|---|---|---|
| Homepage hero | On-demand | CMS publish webhook |
| Product pages | Time + On-demand | 1hr + price change webhook |
| Blog posts | On-demand | CMS publish webhook |
| Navigation | On-demand | CMS publish webhook |
| Exchange rates | Time-based | 5 minutes |
| Static pages | Never | Deploy only |
⚙️ How It Works
On-demand revalidation flow:
- Editor publishes a blog post in CMS
- CMS sends POST to
/api/revalidatewith{ type: 'post', slug: 'my-post' } - Route Handler verifies webhook secret
- Calls
revalidateTag('posts')andrevalidatePath('/blog/my-post') - Next.js marks those cache entries as stale
- Next request to
/blog/my-posttriggers a background rebuild - Fresh HTML served to subsequent requests
💻 Example
Complete Revalidation Setup — A production-ready revalidation webhook with tag-based invalidation.
🤔 Common Confusions
❓ What is the difference between revalidatePath and revalidateTag?
revalidatePath invalidates a specific URL. revalidateTag invalidates all cache entries that used fetch() with that tag. Tags are more powerful — a single CMS publish can revalidate the post page, the blog listing, and the homepage (all tagged with "posts") with one revalidateTag("posts") call.
❓ Does revalidation happen immediately?
revalidatePath and revalidateTag mark cache entries as stale immediately. The actual rebuild happens on the NEXT request to that path. So the current request sees stale data, and the next user gets fresh data. This is stale-while-revalidate behaviour.
❓ Can I call revalidatePath from a Client Component?
No — revalidatePath and revalidateTag are server-only functions. Call them from Server Actions or Route Handlers. A Client Component can trigger a Server Action that calls revalidatePath, or POST to a Route Handler that calls it.
🚨 Common Production Issues
Revalidation not working on self-hosted setups — revalidatePath/revalidateTag work per-server-instance. If you have multiple server instances, only the instance that received the webhook revalidates. Use a shared cache store (Redis) with the Next.js cache handler for multi-instance setups.
Missing the leading slash in revalidatePath — revalidatePath("products/slug") without a leading slash does not work. Always use revalidatePath("/products/slug").
Over-invalidating with broad tags — revalidateTag("all") on a large site triggers rebuilds of thousands of pages simultaneously, causing a server spike. Use specific tags and invalidate only what changed.
✅ Best Practices
Tag every fetch call with at least one meaningful tag — enables precise on-demand invalidation
Use hierarchical tags: ["posts", "post-slug"] — revalidate all or specific
Always verify webhook secrets — an unprotected revalidation endpoint is a DoS vector
Combine time-based (safety net) with on-demand (immediate) revalidation
Log all revalidation events with timestamps for debugging stale content reports
🏛️ Architect's Note
Design your tag taxonomy before writing any fetch calls. A consistent tagging strategy — e.g., ["entity-type", "entity-type-id"] — makes on-demand revalidation predictable and maintainable. Document it in your team's architecture decision records (ADRs).
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
Next.js Technology Guide
Return to the Next.js learning hub.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Full Stack Java Developer Career Path
A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.
Sources
Sources / References
Use these Next.js references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide Next.js learning path
Browse the full Next.js topic collection and learning order on SplashRide.
Next.js Interview Prep
Practice Next.js interview questions and scenario-based answers.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Full Stack Java Developer Career Path
A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.
Incremental Static Regeneration (ISR)
Master ISR — the Next.js feature that gives you static performance with dynamic freshness. Learn time-based and on-demand revalidation for real production systems.
Caching Strategies
Master advanced caching strategies in Next.js — combining SSG, ISR, SSR, and client caching for optimal performance across different content types.