Performance: ISR (Incremental Static Regeneration)
ISR affects page load speed by serving static pages quickly while updating content in the background without blocking user requests.
Jump into concepts and practice - no test required
export async function getStaticProps() { const res = await fetch('https://api.example.com/data'); const data = await res.json(); return { props: { data }, revalidate: 60 }; } // Page served statically and regenerated in background every 60 seconds
export async function getServerSideProps() { const res = await fetch('https://api.example.com/data'); const data = await res.json(); return { props: { data } }; } // Page renders on every request, blocking user until data loads
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Server-side rendering on every request | High (new DOM each request) | Multiple reflows per request | High paint cost due to delay | [X] Bad |
| ISR with revalidate option | Low (cached DOM reused) | Single reflow on initial load | Low paint cost, fast LCP | [OK] Good |
revalidate property inside getStaticProps.getServerSideProps is for server-side rendering, getInitialProps is legacy, and useEffect is a React hook for client-side effects.export async function getStaticProps() {
return {
props: { time: Date.now() },
revalidate: 10,
};
}revalidate: 10 means Next.js will regenerate the page at most every 10 seconds.export async function getStaticProps() {
return {
props: { data: 'Hello' },
revalidate: '60',
};
}revalidate property must be a number representing seconds, not a string.props is correctly an object, getStaticProps can be async, and fallback is unrelated here.revalidate: 300 in getStaticProps and fallback: 'blocking' in getStaticPaths.getServerSideProps with revalidate: 300 uses server-side rendering, not ISR. Use getStaticProps with revalidate: '300' and no fallback has revalidate as string and no fallback. Use getStaticPaths with fallback: false and no revalidate disables fallback and revalidate, so no ISR updates or loading fallback.