ISR allows you to update static content without rebuilding your entire site.
How It Works
- Initial request: Serves the cached page.
- Background revalidation: After the cache expires, Next.js regenerates the page in the background.
- 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
| Static | Dynamic |
|---|---|
| Pre-rendered at build | Generated on-demand |
| Faster TTFB | Fresh data |
| Cacheable at CDN | Requires server |
ISR gives you the best of both worlds: static performance with dynamic freshness.