What if your website could update itself quietly in the background, keeping visitors happy and your work easy?
Why ISR (Incremental Static Regeneration) in NextJS? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have a website with many pages that need to update often, like a blog or store. You try to rebuild the whole site every time something changes, which takes a long time and makes visitors wait.
Rebuilding the entire site manually is slow and wastes resources. Visitors might see outdated content or face delays. It's hard to keep everything fresh without breaking the site or slowing it down.
ISR lets you update only the pages that change, automatically and quickly, without rebuilding the whole site. It combines the speed of static pages with the freshness of dynamic content.
next build && next export # rebuilds entire site every timeexport async function getStaticProps() {
return { props: {}, revalidate: 10 } // updates page every 10 seconds
}You can deliver fast, static pages that update automatically in the background, giving users fresh content without delays.
A news website shows breaking stories instantly by regenerating only the changed articles, while keeping the rest of the site super fast.
Manual full rebuilds are slow and inefficient.
ISR updates pages incrementally and automatically.
This keeps sites fast and content fresh without downtime.
Practice
Solution
Step 1: Understand ISR concept
ISR allows static pages to be updated after the initial build without rebuilding the whole site.Step 2: Compare options
Options B, C, and D describe client-side rendering, disabling static generation, or forcing server-side rendering, which are not ISR features.Final Answer:
To update static pages after build without rebuilding the entire site -> Option CQuick Check:
ISR updates static pages incrementally = A [OK]
- Confusing ISR with client-side rendering
- Thinking ISR disables static generation
- Believing ISR forces server-side rendering
Solution
Step 1: Identify ISR enabling function
ISR is enabled by returning arevalidateproperty insidegetStaticProps.Step 2: Check other options
getServerSidePropsis for server-side rendering,getInitialPropsis legacy, anduseEffectis a React hook for client-side effects.Final Answer:
getStaticProps -> Option BQuick Check:
ISR uses getStaticProps with revalidate = D [OK]
- Using getServerSideProps instead of getStaticProps
- Confusing client-side hooks with data fetching
- Using deprecated getInitialProps for ISR
export async function getStaticProps() {
return {
props: { time: Date.now() },
revalidate: 10,
};
}Solution
Step 1: Analyze revalidate property
Therevalidate: 10means Next.js will regenerate the page at most every 10 seconds.Step 2: Understand page update behavior
The page will serve the static content initially, then update the static page in the background every 10 seconds.Final Answer:
The page updates every 10 seconds with new time -> Option DQuick Check:
revalidate 10 means update every 10 seconds = A [OK]
- Thinking page never updates after build
- Confusing ISR with server-side rendering
- Assuming syntax error due to revalidate
export async function getStaticProps() {
return {
props: { data: 'Hello' },
revalidate: '60',
};
}Solution
Step 1: Check revalidate type
Therevalidateproperty must be a number representing seconds, not a string.Step 2: Verify other parts
propsis correctly an object,getStaticPropscan be async, and fallback is unrelated here.Final Answer:
revalidate must be a number, not a string -> Option AQuick Check:
revalidate type must be number = C [OK]
- Passing revalidate as string instead of number
- Thinking getStaticProps can't be async
- Confusing fallback with revalidate
Solution
Step 1: Understand ISR with fallback
To update static pages every 5 minutes (300 seconds) and show fallback loading for new pages, userevalidate: 300ingetStaticPropsandfallback: 'blocking'ingetStaticPaths.Step 2: Check other options
UsegetServerSidePropswithrevalidate: 300uses server-side rendering, not ISR. UsegetStaticPropswithrevalidate: '300'and no fallback has revalidate as string and no fallback. UsegetStaticPathswithfallback: falseand no revalidate disables fallback and revalidate, so no ISR updates or loading fallback.Final Answer:
Use getStaticProps with revalidate: 300 and fallback: 'blocking' in getStaticPaths -> Option AQuick Check:
ISR with fallback blocking and revalidate 300 = B [OK]
- Using server-side rendering instead of ISR
- Passing revalidate as string
- Setting fallback to false disables loading fallback
