Performance: Revalidation strategies (time-based)
This affects how often the page content is refreshed and how fast users see updated content without blocking the initial load.
Jump into concepts and practice - no test required
export async function getStaticProps() { const data = await fetchData(); return { props: { data }, revalidate: 60 // Rebuild page in background every 60 seconds }; }
export async function getStaticProps() { const data = await fetchData(); return { props: { data } }; } // No revalidation, page rebuilds only at deploy time
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No revalidation (static only) | Minimal DOM nodes | 0 reflows on load | Fast paint but stale content | [!] OK |
| Time-based revalidation (e.g., 60s) | Minimal DOM nodes | 0 reflows on load | Fast paint with fresh content over time | [OK] Good |
revalidate property in getStaticProps do in Next.js?revalidate role in getStaticPropsrevalidate property sets a time interval in seconds for Next.js to regenerate the static page in the background.revalidategetStaticProps?revalidaterevalidate value must be a number representing seconds.getStaticProps:
export async function getStaticProps() {
return {
props: { time: Date.now() },
revalidate: 5
}
}
What will happen if you visit the page multiple times within 3 seconds?revalidate: 5 means Next.js regenerates the page at most every 5 seconds.time value because regeneration hasn't happened yet.time value for all visits within 3 seconds. -> Option Arevalidate: 0 in getStaticProps. What is the problem with this code?revalidate: 0 meaningrevalidate to 0 disables Incremental Static Regeneration (ISR). The page is generated at build time and cached forever without background regeneration.revalidate helps achieve this efficiently?revalidategetStaticProps ensures updates only when content changes, saving resources.revalidate: 60 with Incremental Static Regeneration (ISR) and conditional data fetching. -> Option C