N
Nuxt3mo ago
Quentin

Force browser to not keep chunks in cache

Hi. My users are often facing problems like they still have old version of the website after deployment. If they do hard refresh or cache clear in their browser they got the right version. So I wonder how can i do to force the browsers to clear cache if the files have been re-builded
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Quentin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Nuxt handles browser caching of built assets (chunks) using hashed filenames. When you redeploy your site, Nuxt generates new filenames for changed files, so browsers should automatically fetch the new versions. However, if users are still seeing old versions after deployment, it may be due to aggressive browser or CDN caching. From the available knowledge sources, there is no explicit documentation on forcing browsers to clear their cache or invalidate old chunks beyond the default cache-busting mechanism provided by hashed filenames. However, a recent Nuxt improvement ensures that payloads are now managed using the browser cache, and Nuxt will refetch payloads if the browser cache is cleared or invalidated. This should help with memory usage and cache invalidation for content-driven sites, but it does not directly address chunk caching for JS/CSS files. The cache is safely busted when query parameters change, so Nuxt will refetch payloads as needed if the cache is invalidated by a new deployment or a cache-busting query param is used. This means that, in general, Nuxt is designed to handle cache invalidation for payloads and assets automatically after deployment, as long as the deployment process is standard and the CDN is configured correctly perf(nuxt): use browser cache for payloads. If you are still experiencing issues, you may want to check your CDN or hosting cache settings to ensure they are not serving stale files. Also, make sure you are not overriding the default Nuxt behavior regarding asset filenames and cache headers. In summary:
- Nuxt uses hashed filenames for built assets, which should automatically invalidate old cached files after deployment. - Recent improvements help manage payload cache, but there is no explicit setting to force browsers to clear all cached chunks. - If issues persist, review your CDN and cache headers to ensure they respect the new asset filenames after each deployment. If you need more granular control, such as forcing a cache clear on the client, the knowledge sources do not provide a built-in Nuxt solution for this scenario. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@179707857120395271> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?