The browser reloads the js file, clears the local file, updates the release js cache

Preface: The program js file has been changed. But the browser will not re-download the js file or use the cache when the user uses it. Reloading the file does not work either. Later, I found that the cached data and files can be cleared from the settings, but the user cannot refresh or clear the cache every time. Here is the solution.
1. Modify the file name of js. Maintenance is difficult. not suggested.

2. Add a timestamp or random number after the path.
Generally, a timestamp or random number function is used to generate a value in the html template.

Using timestamp, the value is different every time the html is refreshed. Random numbers are the same

This method is not recommended.
The problem caused by this method is that every time the html is refreshed, the timestamp is changed, and the url is always unique, so the browser always requests the server to obtain the js file, and does not use the browser's local cache. Occupy bandwidth, affect speed

3. Add the version number of js after the path. This is a better approach.
Take the initiative to add time, if this release, which js files have been modified. Then add a time point at the end: year, month, and day.
If the modification of the js file is released multiple times a day, the programmer must be more precise. Year, month, day, hour, minute and second. ?t=20181226

Insert picture description here

Guess you like

Origin blog.csdn.net/hello_mr_anan/article/details/85259113