Incremental Static Regeneration

+15 Mana ✨

ISR allows you to update static content without rebuilding your entire site.

How It Works

  1. Initial request: Serves the cached page.
  2. Background revalidation: After the cache expires, Next.js regenerates the page in the background.
  3. Subsequent requests: Serve the updated page.

Implementation

typescript
// Using fetch with revalidate
async function getData() {
  const res = await fetch('https://api.example.com/data', {
    next: { revalidate: 3600 }, // Revalidate every hour
  });
  return res.json();
}

// Or using the route segment config
export const revalidate = 3600; // seconds

Static vs Dynamic

StaticDynamic
Pre-rendered at buildGenerated on-demand
Faster TTFBFresh data
Cacheable at CDNRequires server

ISR gives you the best of both worlds: static performance with dynamic freshness.

✓ Completed