Incremental Static Regeneration (ISR)

In Next.js, Incremental Static Regeneration (ISR) allows you to update static pages after deployment without requiring a full rebuild. This makes it ideal for performance and SEO on dynamic sites.

🧠 How ISR Works:

  • ISR enables the regeneration of static pages after the site has been deployed.
  • You can define a revalidate time, which tells Next.js how often to re-generate the page in the background.

🔄 Revalidate Time

  • The revalidate field inside getStaticProps specifies the number of seconds to wait before regenerating the page.

Example of ISR using getStaticProps:

javascript
1export async function getStaticProps() { 2 const res = await fetch('https://api.example.com/data'); 3 const data = await res.json(); 4 return { props: { data }, revalidate: 60 }; 5}
  • In this example, the page will be re-generated every 60 seconds in the background when a request is made after the interval.

In short:

  • ISR: Combines the benefits of SSG and dynamic updates.
  • Keeps pages fresh without a full rebuild.
  • Great for blogs, products, and frequently updated content.