Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Incremental Static Regeneration: What It Is

· 7 min read · Home Tech

In this article
  1. Formula
  2. Worked Example
  3. Background: Why ISR Exists
  4. How ISR Works in Practice
  5. Choosing the Right Revalidation Interval
  6. Common Problems and Misconceptions
  7. ISR vs. SSG vs. SSR vs. CSR
  8. Costs and Infrastructure Considerations
  9. Safety and Best Practices
  10. Frequently Asked Questions

Incremental Static Regeneration (ISR) is a website rendering strategy that lets you update static pages after they are built, without rebuilding the entire site. You enter a page URL and a revalidation time, and the system serves a static page immediately while regenerating it in the background when the time expires. This gives you the speed of static files with the freshness of server-rendered content.

in t | Revalidation time | seconds | 60 | 1 | 86400
in n | Pages on site | count | 100 | 1 | 1000000
in r | Requests per page per day | count | 1000 | 1 | 10000000
out build_time | Build time per page | seconds | 2 | 1
out total_build | Full rebuild time | hours | (n * build_time) / 3600 | 2
out bg_regens | Background regenerations per day | count | n * r / t * 86400 | 0

Formula

The core ISR formula is simple: background regenerations per day = (pages × requests per page per day × 86400) / revalidation time. Here, pages is the total number of URLs on your site, requests per page per day is the average traffic per URL, and revalidation time is the ISR interval in seconds (86400 is the number of seconds in a day). The result tells you how many times ISR will rebuild a page in the background daily.

For the full rebuild time, the formula is full rebuild time (hours) = (pages × build time per page) / 3600, where build time per page is how long it takes your static generator to render one URL.

Worked Example

Using the defaults: 100 pages, 1000 requests per page per day, 60-second revalidation, and 2 seconds per page build time.

  1. Background regenerations = (100 × 1000 × 86400) / 60 = 144,000,000 per day.
  2. Full rebuild time = (100 × 2) / 3600 = 0.056 hours (about 3.3 minutes).

That 144 million figure seems huge, but it means every page is regenerated once per minute if it receives traffic. In practice, ISR only regenerates pages that are actually requested after the revalidation time expires, so the real number is far lower.

Background: Why ISR Exists

Before ISR, web developers had two main choices. Static site generation (SSG) built every page at deploy time, producing HTML files that could be cached on a CDN. This was incredibly fast—no server work per request—but any content change required a full rebuild, which could take minutes or hours for large sites. On the other hand, server-side rendering (SSR) generated HTML on each request, which was always fresh but slower and more expensive under traffic.

ISR sits between these. It keeps the static file for instant delivery, but after a set time (the revalidation interval), the next request triggers a background regeneration. The user gets the stale page, and the new version replaces it for subsequent visitors. This was popularized by Next.js in 2020, but the concept—stale-while-revalidate—has existed in HTTP caching for years.

How ISR Works in Practice

When you deploy a site with ISR, the build process creates static HTML for every page. Each page has a revalidate property, often set in seconds. Here’s the request flow:

  1. A user requests /blog/post-1.
  2. The CDN or server checks if the page exists and if the revalidation time has passed.
  3. If the time hasn’t passed, it serves the cached HTML instantly.
  4. If it has passed, it serves the cached HTML anyway, but triggers a background job to rebuild that page.
  5. Once rebuilt, the new HTML replaces the old one on the CDN.

This means users never wait for a build. The trade-off is that content can be up to one revalidation interval stale. For a news site with a 60-second interval, readers might see an article that’s a minute old—acceptable for most cases, but not for live scores or stock prices.

Choosing the Right Revalidation Interval

The interval is the key tuning knob. Too short, and you’re effectively doing SSR, with constant background builds. Too long, and content goes stale. Consider these factors:

  • Content volatility: A product page with inventory counts needs a short interval (30–60 seconds). A blog post about a historical event can use 24 hours.
  • Traffic patterns: Low-traffic pages won’t trigger regenerations often, so a short interval doesn’t hurt. High-traffic pages with a short interval cause many builds.
  • Build cost: Each regeneration runs your data queries and template rendering. If a page queries a heavy database, keep the interval longer.
  • SEO requirements: Search engines prefer fresh content, but a 1-hour interval is usually fine for ranking purposes.

A common strategy is to set a default of 60 seconds for dynamic pages and 3600 (1 hour) for evergreen content. Some frameworks allow on-demand revalidation, where you trigger a rebuild via an API call after a content update—this removes the interval entirely for known changes.

Common Problems and Misconceptions

The biggest misconception is that ISR makes your site “real-time.” It doesn’t—it makes it near-real-time with a delay equal to the interval. Another issue is the stale-while-revalidate stampede: if 1000 users request a page at the exact moment the interval expires, all of them trigger a regeneration, overwhelming your server. Most frameworks deduplicate these requests, but not all do.

Another problem is unpredictable build times. If a page takes 10 seconds to build and your interval is 5 seconds, the rebuild never finishes before the next one starts. You end up with a queue of builds and constant staleness. Monitor your build times and set the interval accordingly.

Finally, ISR doesn’t work well for personalized content. If each user sees a different version of a page, static caching is pointless—you need client-side rendering or SSR with per-user caching.

ISR vs. SSG vs. SSR vs. CSR

Here’s a quick comparison to place ISR in context:

  • SSG: Build once at deploy. Fastest, but content updates require a full rebuild.
  • ISR: Build at deploy, then rebuild individual pages on a schedule. Fast for users, fresh enough for most content.
  • SSR: Build on every request. Always fresh, but slow and expensive under load.
  • CSR: Build in the browser with JavaScript. Flexible, but bad for SEO and initial load speed.

ISR is often described as “SSG with a refresh button.” It’s ideal for sites with thousands of pages where full rebuilds are impractical, like e-commerce catalogs, news archives, or documentation sites.

Costs and Infrastructure Considerations

ISR can reduce costs compared to SSR because the CDN serves most requests without hitting your origin server. However, background regenerations still consume compute time. On serverless platforms, each regeneration is a function invocation, and you pay per invocation. A site with 10,000 pages and a 1-hour interval could trigger up to 240,000 regenerations per day if every page is requested after expiry—though in practice, most pages get far less traffic.

You also need a CDN that supports stale-while-revalidate. Most major providers do, but check your platform’s documentation. Some frameworks implement ISR at the application level, storing generated pages in a database or object storage, which adds latency but gives more control.

Safety and Best Practices

ISR is safe for most content, but avoid it for anything that must be exact: prices with taxes, medical information, legal deadlines, or live inventory. For those, use SSR or client-side fetching. Also, always set a reasonable revalidation time—don’t set it to 1 second unless you have a very good reason and a very fast build.

When you update content, use on-demand revalidation if your framework supports it. This triggers an immediate rebuild for that page, so you don’t have to wait for the interval. Also, add a fallback for pages that don’t exist yet—ISR can generate them on the fly, but you need to handle the “not found” case gracefully.

Frequently Asked Questions

Does ISR work with any static site generator?

No. ISR is a feature of specific frameworks, most notably Next.js. Other frameworks like Gatsby have similar plugins, but the implementation varies. If you’re using a plain static generator like Jekyll or Hugo, you’d need to add a custom CDN layer to achieve the same effect.

What happens if the revalidation time is 0?

Setting revalidate to 0 disables ISR and makes the page behave like SSR—it renders on every request. Some frameworks treat 0 as “never revalidate,” so check your documentation. In practice, you rarely want 0 because you lose the static caching benefit.

Can I use ISR for a page with user-specific data?

Not directly. ISR serves the same HTML to everyone. For personalized content, you’d need to use client-side rendering to fetch user data after the static shell loads, or use SSR with per-user caching. ISR works best for content that is the same for all visitors.

How do I know if my page was regenerated?

Most frameworks add a response header like x-nextjs-cache that shows whether the page was served from cache or regenerated. You can also check the build logs for regeneration events. On a CDN, look for cache-hit vs. cache-miss headers.

Is ISR good for SEO?

Yes, because the HTML is fully rendered and crawlable. Search engines see the static version, which is fine. The only risk is if you set a very long revalidation interval and your content changes significantly—search engines might index stale content. A 1-hour interval is generally safe for most sites.