Performance: Revalidation patterns
This affects how quickly updated content appears on the page and how often the server regenerates pages, impacting load speed and server response.
export async function getStaticProps() { const data = await fetch('https://api.example.com/data'); return { props: { data }, revalidate: 60 // revalidates every 60 seconds }; }
export async function getStaticProps() { const data = await fetch('https://api.example.com/data'); return { props: { data }, revalidate: 1 // revalidates every 1 second }; }
| Pattern | Server Regenerations | Network Delay | LCP Impact | Verdict |
|---|---|---|---|---|
| Revalidate every 1 second | High (every request) | High | High delay | [X] Bad |
| Revalidate every 60 seconds | Low (once per minute) | Low | Low delay | [OK] Good |
| No revalidation | None | Low | Stale content hurts UX | [! ] OK |
| On-demand revalidation | Only on content change | Low | Fast fresh content | [OK] Good |
revalidate export in Next.js control?revalidaterevalidate export sets the time in seconds for Next.js to update a cached page after it was first generated.export const name = value;.export const revalidate = 10;
export default function Page() {
return <div>Time: {Date.now()}</div>;
}revalidate = 10, Next.js caches the page and only regenerates it after 10 seconds.export const revalidate = '30';
export default function Page() {
return <div>Hello</div>;
}revalidate export expects a number representing seconds, not a string.export const revalidate = ?;
Pass the test and this pattern moves unknown