Clear the cache of CSS, JavaScript, and background images in the browser

Source: Internet
Author: User

In the actual project development process, the page is uploaded to the server. In order to reduce the pressure of the server, so that users load less, the browser will be the picture, CSS, JS cache to the local, so that the next time to visit the site to use. This not only reduces the pressure on the server, but also reduces the number of downloads for the user and gives a better user experience.

However, in the version upgrade or do some CSS, JS and other adjustments, the cache caused the user can not display the updated style, this is another head headache. Unless the user manually upgrade the cache, but almost all users will not be able to access the site to manually clear the cache, because users do not know whether the cache is a problem, and ultimately, the user is thinking that your page is a problem, not normal access.

In order to be able to use the cache normally, and avoid such problems, we can think about it, if we solve this problem?

If changes to the style are not properly accessed, then change the file name of the style? The answer is yes, it will not be verified here. However, it is obviously too cumbersome to manually change the file name each time, can not change the file name? The answer is yes. We may add the version number after the introduced file name, which is different from the previous version (typically the update date). The code is as follows:

<link rel= "stylesheet" type= "Text/css" href= "reset.css?v=20140829" ><script type= "Text/javascript" src= " core.js?v=20140829 "></script>

Can see my CSS file name and JS file name followed by "v=20140829", so do not change the file name and cache, can be updated in real time. and "v=20140829" is only the general habit of writing, can be changed to other.

Finally, the image of the general IMG tag will not be the same name, because it is generated in the background file names. And if it is a fixed file name picture, the same way. For the background map, because the style name changed, the resolution path of the image is the update synchronization, so the background map is also updated.

Clear the cache of CSS, JavaScript, and background images in the browser

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.