Performance: Cache invalidation strategies
HIGH IMPACT
This affects page load speed by controlling how fresh content is served and how often the browser or server must fetch new data.
export async function getStaticProps() { const data = await fetch('https://api.example.com/data').then(res => res.json()); return { props: { data }, revalidate: 60 } // Revalidate every 60 seconds }
export async function getStaticProps() { const data = await fetch('https://api.example.com/data').then(res => res.json()); return { props: { data } }; } // No revalidation or cache control, content can become stale indefinitely
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No cache invalidation | Minimal | 0 | Low but stale content delays perceived load | [X] Bad |
| ISR with revalidate | Minimal | 0 | Low with fresh content | [OK] Good |
| Client fetch without cache | Minimal | 0 | Blocks interaction due to network delay | [X] Bad |
| Client fetch with cache | Minimal | 0 | Fast response improves interaction | [OK] Good |
| Static assets no cache headers | N/A | N/A | High due to repeated downloads | [X] Bad |
| Static assets with long cache | N/A | N/A | Low, instant load on repeat visits | [OK] Good |