Why on-demand
Time-based ISR means users might see stale data for the whole revalidate window. On-demand revalidation lets you invalidate the cache the instant a mutation lands — so editors who change content see the new version immediately.
Two functions, two scopes
| Function | Invalidates |
|---|---|
revalidatePath(path, type?) | A specific path. type can be 'page' (just the leaf) or 'layout' (everything under). |
revalidateTag(tag) | Every fetch tagged with tag via fetch(url, { next: { tags } }). |
Where you can call them
Server Actions and Route Handlers only. v15 made this strict; calling them during render throws. The reason: invalidation is a side effect that belongs to mutations, not to pure rendering.