Performance: Opting out of caching
This affects page load speed and server response time by disabling cache reuse, causing repeated data fetching or rendering.
export const revalidate = 60; export default async function Page() { const res = await fetch('https://api.example.com/data', { next: { revalidate: 60 } }); const data = await res.json(); return <div>{data.value}</div>; }
export const revalidate = 0; export default async function Page() { const res = await fetch('https://api.example.com/data', { cache: 'no-store' }); const data = await res.json(); return <div>{data.value}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching (revalidate=0) | Same DOM nodes each request | Multiple reflows due to delayed HTML | Higher paint cost due to slower load | [X] Bad |
| Caching enabled (revalidate>0) | Same DOM nodes reused | Single reflow on initial load | Lower paint cost due to faster load | [OK] Good |
revalidate export to control caching duration for static pages.revalidate to zerorevalidate = 0 tells Next.js to never cache and always fetch fresh data.export const revalidate = 0; in the page file -> Option Drevalidate.export const revalidate = 0;
export default function Page() {
return <h1>Fresh Content</h1>;
}revalidate = 0, which disables caching.const revalidate = 0;
export default function Page() {
return <div>No Cache</div>;
}revalidate must be exported to affect caching.export, Next.js ignores the variable and uses default caching.export const dynamic = 'force-dynamic'; forces server-side rendering, allowing auth checks per request.export const revalidate = 0; unconditionally in the page file disables caching for all users; Set revalidate = 0 inside getStaticProps conditionally is invalid because revalidate is static; Add Cache-Control: no-store header in _app.js for all requests affects all requests globally.export const dynamic = 'force-dynamic'; and check auth inside -> Option CPass the test and this pattern moves unknown