After the introduction of the CSS or JS file add the role of parameters

Source: Internet
Author: User
Sometimes you may encounter JS or CSS file references after passing parameters:

CSS and JS with parameters (shaped like. css?v= and. js?v=)

<script type= "Text/javascript" src= "jb51.js?version=1.2.6″></script>

<link rel= ' stylesheet ' href= "http://www.php1.cn/" >

There are two possible ways to use parameters:

First, the script does not exist, but the server is dynamically generated, so with a version number, to show the difference. That is, the above code is equivalent to the file <script type= "Text/javascript" src= "jb51.js" ></script> <link rel= ' stylesheet ' href= " http://www.php1.cn/">

Second, the client will cache these CSS or JS files, so each time you upgrade the JS or CSS files, change the version number, the client browser will re-download the new JS or CSS files, the role of the brush cache. We may sometimes find that the change of style or JS, the time of the refresh is not changed, that is, the client cache css or JS files, so plus the parameters are good!

The second situation is the most, and it is possible that both exist simultaneously.

The version number can be a random number, or it can be an incremented value, a large version of the iteration, or according to the script's generation time, such as 20080727182553 is accurate to generate script seconds, and 2.3.3 is a large version of the way the small version.

First-time Upgrade:

<script src= "aaa.js?v=1.0" ></script>

Second Upgrade:

<script src= "aaa.js?v=1.1" ></script>

Third-time Upgrade:

<script src= "aaa.js?v=1.2" ></script>

......

Where "V" is just a name, take it casually. This workaround is similar to the principle of adding random numbers after the AJAX request address, allowing the browser to think of accessing different addresses so that cached files are not used.

For example, Sina homepage in the April 5, 2010 revision, just change the CSS style sheet, can be behind the CSS, such as. css?2010.4.5, so that users do not clean the cache to open the Sina home page will not be the same as before, When the server reads the CSS file, it re-reads the latest 2010.4.5,

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.