On-demand revalidation allows you to purge the cache for an ISR route whenever you want, foregoing the time interval required with background revalidation.
To revalidate a page on demand with Next.js:
- Create an Environment Variable which will store a revalidation secret
- Create an API Route that checks for the secret, then triggers revalidation
The following example demonstrates an API route that triggers revalidation if the query paramater ?secret
matches a secret Environment Variable: