Incremental Static Regeneration (ISR)

SSG with timed revalidation that regenerates pages in the background. Excellent for Catalogs, News sites, and Product listings that need periodic updates without full rebuilds.

Server

🌐
Request
Response
πŸ–₯️
Server checks cache
Cache valid or expired
Server fetches data
React.renderToString()
Server stores in cache
Server sends rendered HTML

Client

Client receives HTML
React.hydrate()
✨Page interactive
Benefits x Trade-offs

Benefits

  • β€’Best of Both Worlds: Static performance + dynamic updates
  • β€’Automatic Revalidation: Content stays fresh
  • β€’Scalable: Handles traffic spikes gracefully
  • β€’Cost Efficient: Reduced server load

Trade-offs

  • β€’Brief staleness: Content may be slightly outdated
  • β€’Revalidation overhead: Background regeneration costs
  • β€’Complex caching: Need to manage revalidate times
  • β€’First request delay: May trigger regeneration
How to implement?

ISR uses async Server Components with page-level revalidation. Use generateStaticParams for dynamic routes.

export const revalidate = 3600; // 1 hour

export async function generateStaticParams() {
  return [{ id: "1" }, { id: "2" }];
}

export default async function ISRComponent({ params }: { params: { id: string } }) {
  const res = await fetch("https://api.example.com/data");
  const data = await res.json();

  return <div>{data.message}</div>;
}
  • β€’Components are async functions (no 'use client' directive)
  • β€’Cannot use React hooks (useState, useEffect, etc.)
  • β€’Add 'export const revalidate = 3600' at page level (1 hour)
  • β€’Use generateStaticParams() for dynamic routes
  • β€’Use revalidatePath() or revalidateTag() for on-demand revalidation