What is on-demand revalidation in Next.js, and how is it different from time based revalidation?
Short answer
Time based revalidation refreshes cached content automatically after a set number of seconds, while on-demand revalidation lets you manually trigger a cache refresh at the exact moment your content actually changes, such as right after publishing a new blog post, giving you…
Advertisement
AModel answer
Time based revalidation refreshes cached content automatically after a set number of seconds, while on-demand revalidation lets you manually trigger a cache refresh at the exact moment your content actually changes, such as right after publishing a new blog post, giving you precise control over when fresh data appears.
// Time based: refreshes automatically every 60 seconds
fetch(url, { next: { revalidate: 60 } });
// On-demand: refreshes only when you trigger it
revalidatePath('/blog');Real-world example
A news website uses on-demand revalidation to instantly update its homepage the moment an editor publishes breaking news, rather than waiting up to a minute for the next scheduled time based refresh.
Likely follow-ups
- When would time based revalidation be a better choice than on-demand?
- Can you combine both time based and on-demand revalidation on the same page?
Related topics