Home  >  Article  >  Web Front-end  >  The function of adding parameters after the imported css or js file

The function of adding parameters after the imported css or js file

高洛峰
高洛峰Original
2016-11-24 09:44:501170browse

Sometimes you may encounter js or css file references and then pass parameters:

css and js have parameters (in the form of .css?v= and .js?v=)

Use parameters There are two possibilities:

First, the script does not exist, but is dynamically generated by the server, so a version number is included to show the difference. That is, the above code is equivalent to .php1.cn/">

Second, the client will cache these css or js files, so every time the js or css file is upgraded and the version number is changed, the client browser will re-download the new js or js file. css file, the role of flush caching. You may sometimes find that if you modify the style or js, it will not change when refreshing, that is, the client caches the css or js file, so adding parameters is still beneficial!

The second situation is the most common, or both may exist at the same time.

The version number can be a random number, or an incremental value, in the form of a large version or a small version, or written according to the generation time of the script. For example, 20080727182553 is accurate to the second when the script is generated, and 2.3.3 It's the way of big version and small version.

First upgrade:

Second upgrade:

The third upgrade:

...

Among them, "v" is just a name, take it whatever you want. This solution is the same as adding a random number after the ajax request address, which makes the browser think that a different address is being accessed, so that the cached file will not be used.

For example, the Sina homepage was revised on April 5, 2010. It only changed the CSS style sheet, which can be behind the CSS, such as .css?2010.4.5. In this way, users who have not cleared the cache will not open the Sina homepage as before. When the server reads the CSS file, it will re-read the latest 2010.4.5,


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn