DEV Community

Discussion on: Fixing ChunkLoadError

Collapse
 
jpswade profile image
James Wade

We've also experienced this issue. I wondered why I'd not really experienced this kind of thing before. Usually it's because the site is behind CloudFlare which handles this at CDN level for me.

So I figure the easiest thing to do is just to get nginx to act more like a CDN and ask the browser to hold on to the js/css files for longer.

This is my proposed solution:

location ~* \.(?:css|js)$ {
    add_header Cache-Control "public, max-age=7200";
}
Enter fullscreen mode Exit fullscreen mode

This will tell the browser to cache the files for 2 hours, hopefully by that time, the browser will have refreshed the page and got the new files.

Another idea might be to use a service worker to tell the client that there's a new version of the files and hard refresh.

Hope this helps someone to look at the problem in a slightly different way.