How to obtain the latest version of javascript files, browser cache to resolve the problem

Reprinted from: https://www.cnblogs.com/mafengzi/p/10464910.html

Suppose you have a js file (with jquery for example), URL address on the server is: ../ js / jquery.js.

When the day jquery version update, use the latest version of the documents covered jquery jquery older version of the original file.

Then, when you open a Web page references this js file, there may be cited or older version, because browsers cache, it caches the old version of jquery file.

Browser cache files are complete URL to the cache, that is, when the browser encounters a URL entirely consistent with the previous request, it is possible to use previously cached file instead of to the server to request the file. Of course, there is a cache of aging, after more than a certain amount of time, the cache will disappear.

Since the cache is full URL to the file, then we can use different file names to access the updated file.

One solution is to write the version number in the file name, for example, more than jquery.js file name can be changed to jquery-3.3.0.js, which, jquery 3.3.0 is the version number. When the front end of quote, write:

<script src="../js/jquery-3.3.0.js"></script>

When one day version of jquery 3.3.1 update, we will modify the file name for the jquery-3.3.1. While the front-end code-referenced amended as follows:

<script src="../js/jquery-3.3.1.js"></script>

Another solution is not to change the file name, but the version number on the query parameters in the URL, for example, write:

<script src="../js/jquery.js?ver=3.3.0"></script>

Where ver = 3.3.0 is the version number. When the version number is 3.3.1 update jquery, rewrite it this way:

<script src="../js/jquery.js?ver=3.3.1"></script>

 

Guess you like

Origin www.cnblogs.com/html5study-1/p/11962171.html