What is Incremental Static Regeneration (ISR)
Incremental Static Regeneration (ISR) is a feature of Next.js that allows you to update static pages after they have been built β without rebuilding the entire site.
It combines the best parts of:
π Static Site Generation (SSG) β Fast, pre-built pages
π Server-Side Rendering (SSR) β Fresh, dynamic data
π§ Why ISR Was Needed?
Normally:
MethodProblemSSGContent becomes outdated unless you rebuildSSRSlower because page is generated on every request
ISR solves this by:
Regenerating pages in the background after a specified time.
βοΈ How ISR Works
Page is pre-rendered at build time
You define a revalidate time (e.g., 60 seconds)
After that time:
First user still gets the old cached page
In the background, Next.js regenerates the page
Next users get the updated version
π§© Simple Example (Next.js)
export async function getStaticProps() {
const data = await fetchSomeAPI()
return {
props: { data },
revalidate: 60, // regenerate page every 60 seconds
}
}This means:
Page is static
But will update every 60 seconds automatically
π₯ Real-Life Example
Imagine you are building:
π E-commerce product pages
π° Blog posts
π Dashboard landing pages
You donβt want:
To rebuild your entire site every time a product price changes
Nor to render everything on each request
ISR gives you:
β‘ Static speed + π Fresh data
π― When Should You Use ISR?
Use ISR when:
β Content updates occasionally
β SEO is important
β You want CDN caching
β You donβt need real-time updates
Avoid ISR when:
β You need real-time data (e.g., stock trading dashboard)
Comments (0)
Login to leave a comment.