Keep .js chunks from old deploys

I have an issue with static js files is removed after deploy. I use code spitting to some components in my app (

The app is a web app, and some users have “installed” it on their home screens to use it as a native app.

When lazy loading parts of the web app, a user may browse around during a deploy. All .js chunks are replaced with new hashes when I deploy. When the user (with the old app) now navigates to some functionality that needs to load a chunk, the chunk with that hash does not exists on the server anymore.

So for currently loaded client, the chunk does not exist. Error: Loading chunk 7 failed.

For tech savvy users using the app in a browser, they can just refresh. But for those users who are using the app “installed” on their home screen, they can’t reload the page.

One solution would be to force refresh the app when a chunk fails to load, like this solution

But in addition, it would be great to keep old js chunks on the server for a while.

Is there a way to deploy a react app without wiping the old static files (except those that are overwritten, of course)?

Hi, @stianlp. Our deploys are “atomic” so that the old assets are expired when the new deploy is publish. There is more information about this here and here.

The only way I know of to keep the previous files active would be to include them in the publish directory of the new deploy.

Keeping the old files active is the opposite behavior of what Netlify will do by default and there is no automatic method for doing this.

The best solution I can think of is to have the site javascript check the version of the deployed site (using the etag header for some file, for example /index.html) and force an update of all assets when the etag changes.

You might also copy all files from all previous deploys to the new deploy but, again, this runs contrary to Netlify’s design and there is no automated solution do this.

If there are other questions about this, please let us know.