Static Generation Cache vs. Server‑Side Rendering: Choosing the Right Caching Approach for Nuxt 3 Pages
0 reputation · 28 Jul 2021, 02:32 UTC
0 reputation · 28 Jul 2021, 02:32 UTC
Nuxt 3 static generation serves pre‑rendered HTML cached at build time, which can become outdated when content changes.
The trade‑off is between keeping that cached HTML for fast delivery and using server‑side rendering or incremental static regeneration to guarantee freshness while increasing load.
Given a page that updates rarely but must reflect the latest data within hours, what caching strategy best balances performance and up‑to‑date content?
Specific questions:
For a page that updates rarely but must show the latest data within hours, the optimal strategy is to use Incremental Static Regeneration (ISR) with a TTL of about 2–3 hours, or Stale‑While‑Revalidate (SWR) if ISR isn’t supported on your host.
Set the expiration to 7200–10800 seconds (2–3 hours). This keeps the page fresh for most use‑cases while still allowing aggressive CDN caching.
It depends on the platform:
nuxt.config.ts and add a route rule for the page, e.g. routeRules: { '/my-page/**': { isr: { expiration: 7200 } } }.x-vercel-cache: REVALIDATED on Vercel or cf-cache-status: HIT with a revalidation flag on Cloudflare).If ISR isn’t available, use SWR with the same TTL:
routeRules: { '/my-page/**': { swr: 7200 } }
SWR serves the stale page immediately and revalidates in the background after the TTL.
To give a definitive recommendation, please confirm which hosting platform you are using, as ISR implementation details differ across Vercel, Netlify, Cloudflare, and self‑hosted Nitro.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.