codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
▲

Next.js

13 / 73 topics
10Data Fetching Methods (getStaticProps, getServerSideProps)11Static Site Generation (SSG)12Server-Side Rendering (SSR)13Incremental Static Regeneration (ISR)14Client-Side Data Fetching15SWR Library for Client-Side Data Fetching
Tutorials/Next.js/Incremental Static Regeneration (ISR)
▲Next.js

Incremental Static Regeneration (ISR)

Updated 2026-04-20
3 min read

Incremental Static Regeneration (ISR)

Incremental Static Regeneration (ISR) is a feature introduced by Next.js that allows you to statically generate pages at build time but also update them periodically without needing to rebuild the entire site. This hybrid approach between static generation and server-side rendering provides the best of both worlds, offering fast page loads and up-to-date content.

Overview

In traditional static site generation (SSG), pages are generated once during the build process and remain unchanged until the next build. While this results in excellent performance, it can lead to outdated content if the data changes frequently. ISR addresses this issue by allowing you to regenerate specific pages at a defined interval, ensuring that your users always see the most recent information.

How ISR Works

ISR uses the generateStaticParams function and the revalidate option. When you set revalidate, Next.js will automatically update the page in the background at the specified interval. This means that subsequent requests to the page will fetch fresh data, and the updated content will be served to users.

Setting Up ISR

To enable ISR, follow these steps:

  1. Create a Static Page: Use generateStaticParams to fetch initial data.
  2. Add Revalidation: Set the revalidate option in your route configuration.

Example Code

Here's an example of how to set up ISR for a blog post page using the App Router:

// app/posts/[id]/page.js

import { notFound } from 'next/navigation';

export async function generateStaticParams() {
  // Fetch all posts IDs
  const res = await fetch('https://api.example.com/posts');
  const posts = await res.json();

  // Generate paths for each post
  return posts.map((post) => ({
    id: post.id.toString(),
  }));
}

export default async function Post({ params }) {
  const { id } = params;
  const res = await fetch(`https://api.example.com/posts/${id}`, {
    next: { revalidate: 10 }, // Revalidate every 10 seconds
  });

  if (!res.ok) {
    notFound();
  }

  const post = await res.json();

  return (
    <div>
      <h1>{post.title}</h1>
      <p>{post.content}</p>
    </div>
  );
}

Explanation

  • generateStaticParams: This function is used to generate the paths for static pages. It fetches all post IDs and returns them as an array of objects with id.
  • fetch with revalidate option: The revalidate option is set to 10 seconds, meaning the page will be regenerated every 10 seconds.
  • notFound: This function is used to handle cases where a post is not found.

Best Practices

  1. Choose the Right Revalidation Interval: The revalidate interval should balance between performance and freshness. A shorter interval ensures more up-to-date content but may increase server load.
  2. Optimize Data Fetching: Use efficient data fetching strategies, such as caching or batching requests, to reduce server load and improve performance.
  3. Monitor Performance: Keep an eye on your application's performance metrics to ensure that ISR is not causing unexpected issues.

Real-World Applications

ISR is particularly useful for applications where content changes frequently but doesn't require real-time updates. Some examples include:

  • News Websites: Blogs, news sites, and other platforms that publish new articles regularly.
  • E-commerce Sites: Product pages that need to reflect stock levels or pricing changes quickly.
  • Dashboards: Analytics dashboards that display up-to-date metrics.

Conclusion

Incremental Static Regeneration is a powerful feature in Next.js that allows you to serve static pages with dynamic content. By setting the revalidate option, you can ensure that your users always see the most recent information without compromising performance. With careful implementation and monitoring, ISR can significantly enhance the user experience of your application.

By following the guidelines and best practices outlined in this tutorial, you'll be well-equipped to implement ISR in your Next.js projects and take advantage of its benefits.


PreviousServer-Side Rendering (SSR)Next Client-Side Data Fetching

Recommended Gear

Server-Side Rendering (SSR)Client-Side Data Fetching