Update JS and CSS in user browser automatically

Viewed 39

We are making changes in our Angular application and pushing into production every day.

The problem: users have to reload the page to load the updated files. This is not about caching, simply F5.

What is the best way to automatize page reloading if any change in frontend available?

We have come up with the following idea: store the "version" in the database. Also store the "version" in Local Storage. Compare these values each request to the backend. If they differ - reload the page.

1 Answers

If you are using npm/webpack, you have to update the "version" in your package.json. Else, you can just put a version like 1.N.N at the end of your css or js files before the .extension. Changing names will force the browser to update assets files content. Next, you just have to manually (programmatically with ci/cd) update theses versions in the file names before you deploy in production.

Related