Nuxt tips
5 tips · newest first
Nuxt tips on data fetching, SSR state safety, Nitro caching, and hybrid rendering — small patterns that prevent double-fetches and leaks.
Cache expensive server routes at the edge with defineCachedEventHandler
NUXTNitro's defineCachedEventHandler wraps a server route with stale-while-revalidate caching backed by your configured sto…
Set per-route rendering strategy with routeRules instead of restructuring code
NUXTrouteRules applies a rendering mode per URL pattern in config, so marketing pages prerender, content pages use ISR, and…
Give useAsyncData an explicit key to control dedup and caching
NUXTuseAsyncData dedups and caches by key. Without an explicit key Nuxt derives one from the call site, which can collide w…
Share state across components with useState, never a module-level ref, on SSR
NUXTOn the server a module-level ref is created once and shared by every request, so one user's cart can leak into another'…
Use useFetch in setup and $fetch in handlers to avoid double-fetching
NUXTuseFetch is the SSR-aware wrapper: it runs during server render, serializes the result into the payload, and hydrates o…