Problem Statement
Explain the difference between time-based revalidation and on-demand revalidation in Next.js.
Explanation
Time-based revalidation uses the revalidate option in getStaticProps specifying seconds after which Next.js should check for updates, automatically regenerating pages in the background when the time expires and a request arrives, suitable for content that updates on a predictable schedule.
On-demand revalidation uses the revalidatePath or revalidateTag API routes methods to programmatically trigger page regeneration immediately when content changes, like when a webhook from your CMS signals updated content, providing instant updates without waiting for the revalidate timer.
On-demand revalidation is more efficient and provides better UX since users see fresh content immediately after changes rather than waiting for the next revalidation window, but requires setting up webhooks or API routes to trigger revalidation.
Use time-based for regular predictable updates and on-demand for immediate updates when content changes, and combine both approaches for robust content synchronization.
Practice Sets
This question appears in the following practice sets: