JS, CSS, IMG and other browser caching problems 2 solutions _javascript Tips

Source: Internet
Author: User
Tags browser cache
Details determine success or failure! The meaning of browser caching is to improve the execution efficiency, but it also brought some problems, resulting in the service side modified JS, CSS, the client can not update
method to generate a random number
Copy Code code as follows:

<script type= "Text/javascript" src= "/js/test.js?+math.random ()" ></script>

Disadvantage, the browser cache loses its meaning, dynamically loading each time.

Method Two version number control, set the global variable, each release before the version number plus 1
Copy Code code as follows:

<script type= "Text/javascript" src= "/js/test.js?v=<%=v%>" ></script>

This practice is recommended in a relatively simple way. The disadvantage is that the HTML page is not available, but this page should not be too much

More methods: The use of reading file size, file modification time to generate MD5 automated implementation, automatic construction of the program compression merge JS and the global replacement version, the way is complex, interested can study

Who else has a better way?
Related Article

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.