Tuning Next.js Incremental Static Regeneration for Fresh Content Without Full Rebuilds
Next.js ISR lets static pages refresh in the background after a set interval. Learn how revalidate works, when it needs a server, and how to avoid common interval and fallback mistakes.
25 Sept 2025, 11:53 UTC

A statically generated site becomes outdated the moment your content changes, but rebuilding the entire site for every update is slow and wasteful. The practical takeaway: Next.js Incremental Static Regeneration (ISR) lets individual pages refresh themselves in the background after a set interval, so visitors see cached content immediately while the updated version is generated asynchronously. You control this by exporting a revalidate value from getStaticProps.
How ISR Works: Stale-While-Revalidate for Static Pages
ISR follows a stale-while-revalidate pattern. When a request arrives for a page that was generated at build time, Next.js checks whether the revalidate window has elapsed. If it has, the framework serves the existing static HTML immediately and triggers a background regeneration. Once the new page is ready, it atomically replaces the cached version. The next visitor sees the fresh content. If regeneration fails, the old page remains in place and the error is logged.
The key detail is that revalidate is a minimum interval, not a schedule. If no request arrives after the interval, regeneration does not happen. If a request arrives one second after the window closes, regeneration starts then.
A Worked Example: Regenerating a Page on a 60-Second Interval
The following example uses the Pages Router (pages/ directory). It assumes a product detail page backed by an external API.
// pages/products/[id].js
export async function getStaticPaths() {
const res = await fetch('https://api.example.com/products');
const products = await res.json();
const paths = products.map((product) => ({
params: { id: product.id },
}));
// fallback: 'blocking' means new paths not built at build time
// will be server-rendered on first request, then cached.
return { paths, fallback: 'blocking' };
}
export async function getStaticProps({ params }) {
const res = await fetch(`https://api.example.com/products/${params.id}`);
const product = await res.json();
return {
props: { product },
revalidate: 60, // seconds
};
}
The revalidate: 60 tells Next.js to regenerate this page at most once every 60 seconds, and only when a request arrives after that window. The fallback: 'blocking' in getStaticPaths is required if you expect paths that were not present at build time; without it, new product IDs would return a 404 until the next full build.
Limits: Where ISR Needs a Server, Not Just a CDN
ISR requires a runtime that can execute background regeneration. It is not available on pure static hosts that only serve pre-built files. While some standalone output configurations may work with compatible hosts, the standard approach is to run next start on a Node.js server or deploy to a platform with serverless function support. If your deployment produces only a folder of HTML files with no server process, ISR will not function.
Version differences matter. In the Pages Router, you use getStaticProps with revalidate. In the App Router (Next.js 13+), the mechanism differs: you can set revalidate in fetch options or use route segment config. The two are not fully equivalent, and edge runtime support varies. Verify the API signatures for your installed version before relying on them.
Self-hosted clusters introduce another constraint. If you run multiple Next.js instances behind a load balancer, a regeneration on one instance may not be visible to the others unless you use a shared cache layer. Platforms such as Vercel provide a distributed cache that handles this automatically; self-hosted deployments need an external cache such as Redis.
Large sites may also hit platform limits on concurrent regenerations or function execution duration. If you have thousands of ISR pages, test your host's concurrency limits before assuming every page can regenerate simultaneously.
Common Mistakes: Intervals, Fallback Paths, and Version Differences
- Setting
revalidatetoo low. A value of 1 second causes a background regeneration on nearly every request, multiplying API load and compute cost. Choose an interval that matches your content's actual change frequency and your API's rate limits. - Forgetting
fallback. IfgetStaticPathsreturns only build-time paths and omitsfallback, new dynamic routes will 404. Usefallback: 'blocking'ortruewhen new paths are expected. - Assuming on-demand revalidation is automatic. You can trigger an immediate purge by calling
res.revalidate('/path')from an API route, but you must wire that endpoint to your CMS webhook yourself. It is useful for webhook-driven updates from a headless CMS, but it is not enabled by default. - Mixing Pages Router and App Router APIs. The
getStaticPropspattern does not exist in the App Router. If you migrate directories, update your data-fetching strategy accordingly.
Verifying the Behavior on Your Host
To check ISR locally, run the following commands in your project directory. You need Node.js installed and project dependencies already present.
npx next build
npx next start
Then request the page, wait longer than your revalidate interval, and request it again. Expected check: the first request after the interval serves the cached page quickly, and the background regeneration completes before or shortly after the response. If the page never updates, confirm your host supports ISR and that you are not using a pure static export.
For on-demand revalidation, create an API route that calls res.revalidate() and trigger it with a command like the following, replacing the port and path with your values:
curl -X POST http://localhost:3000/api/revalidate?path=/products/123
Because ISR behavior and API signatures have changed across Next.js versions, verify the exact syntax against the documentation for your installed version before deploying to production. Hosting support also varies: confirm that your target platform implements background regeneration before relying on it.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.