About updating the cache of CSS and JS files

Source: Internet
Author: User

In the Web application of the world today, most of our programmers work based on the B/s architecture, B/S Architecture advantage is to update the page and background logic in time (even at any time), without notifying the customer to manually update the client. In this environment, is not B/s architecture software really does not upgrade the problem?

Now, browser war, each browser is also a life-enhancing performance, upgrade the JS parsing engine, better handle the browser page cache, so that the user's browsing experience faster, occupy smaller PC resources. Then, the problem is in the JS and CSS cache, and even the page cache. As for the browser to the page cache, we generally set the page's lifetime by sending the page on the server, generally a few hours can alleviate the great pressure of the servers, and, for the viewer, the local page late update a few hours may not be a problem. However, the problem is, if the page has been updated, but the page linked to the JS and CSS files are cached by the browser, only to be deleted after the browser restart, and even some browser restarts will not actively delete the JS and CSS cache files. This way the page and JS and CSS files can be disjointed, resulting in some anomalies, and even the page crashes. The more pit dad phenomenon is, now users in order to save their work (entertainment) state, at all for a long time not shutdown, of course, do not close the browser. This has made the problem even more serious.

Here is a simple and common caching solution for JS and CSS:

Note that each JS file and CSS file above are prefixed with a timestamp as the version number.

That

<script type= "Text/javascript" src= "{JS File connection address}?version=xxxxxxxx" ></script>

Or
<link rel= "stylesheet" type= "Text/css" href= "{CSS File connection address}?version=xxxxxxxx" >

Because the browser caches the URL as a storage unit (remember the Post page Back button problem?). ),

Thus, each time the first page of the file is updated only need to change the above version number, you can remind the browser to download the file again.

About updating the cache of CSS and JS files

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.