B
B
bellerofonte2017-03-12 20:40:05
JavaScript
bellerofonte, 2017-03-12 20:40:05

How to tell the browser that the site has changed and the cache needs to be refreshed?

There is a small site written in React.js, which is hosted on a Linux virtual machine under apache2. Periodically, as needed, its source code changes, is collected by webpack, and copied to the virtual machine. After each update, all users using the site have to clear the cache (and hard reset in Chrome) in order to access the new functionality. As expected, users forget to do this. How can the user's browsers be notified that the site code has changed and the cache needs to be updated automatically?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xutesayor, 2017-03-12
@bellerofonte

Where your js file is included, add the version number in the parameters. For example:
If you wish, you can automate this business

A
amiksam, 2017-03-18
@amiksam


https ://developers.google.com/web/fundamentals/per... for index.html we generally disable caching, and cache js files (you can do it forever).
When building, we add a hash to the js / css file, which will change when the file changes. This way index.html will always be picked up. If there is a link to a new assembly, then new scripts / styles will be downloaded, otherwise they will be taken from the browser cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question