This article for you in detail the next JS in the automatic removal of IE cache of several methods, we can according to their own needs free choice for their own, hope to learn JS to help you
automatic removal of IE cache method in JS- common
For dynamic files, such as index.asp?id= ... Or index.aspx?id= ... It is believed that experienced programmers know how to prohibit the browser from caching data.
But for static files (css,jpg,gif, etc.), under what circumstances do we need to prohibit the browser from caching them, how to do?
method One: In Dojo we can do this in a simple way: the Dojo.xhrget (including post) includes the Preventcache attribute, meaning: "Browser caching is enabled by default, otherwise the browser cache will be invalidated by automatically adding different parameters" We just have to assign this property: "true".
method Two:document.write ("
The 113 of ver=113 is the version number, which is typically the development version number that was generated using CVS or other tools.
This really does what should be cached when the static file is cached when the version is updated from the latest version, and the cache is updated.
For images to efficiently utilize and update the cache.
JS Clear Browser Cache two
In order to reduce the network pressure between the browser and the server, often the static files, such as JS,CSS, modified images do the cache, that is, the HTTP response header to these files to add the expires and Cache-control parameters, and specify the cache time, For a certain time, the browser will not send any HTTP requests to the server (in addition to forced refresh), even during this time the server's JS or CSS or picture files have been updated several times, but the browser data is still the original cache of old data, Is there a way for the browser to get the latest data that has been modified?
Yes, the method is to use AJAX to request the latest server files, and add the request header if-modified-since and Cache-control, as follows:
Copy CodeThe code is as follows:
$.ajax ({
Type: "GET",
URL: "Static/cache.js",
DataType: "Text",
Beforesend:function (xmlHttp) {
Xmlhttp.setrequestheader ("If-modified-since", "0");
Xmlhttp.setrequestheader ("Cache-control", "No-cache");
}
});
jquery was used here.
In this way, the browser will replace the latest files with the old local files.
Of course, there is a problem here is that JS must know that the server updated the JS, CSS, pictures, using cookies and time version should be able to solve.
jquery has ifmodified and cache parameters since 1.2, so you don't have to add headers.
Ifmodified Boolean Default:false
Allow the request is successful only if the response have changed since the last request. This is do by checking the last-modified header. Default value is false, ignoring the header.
Cache Boolean Default:true
Added in JQuery 1.2, if set to false it would force the pages of this you request to not being cached by the browser.
Copy CodeThe code is as follows:
$.ajax ({
Type: "GET",
URL: "Static/cache.js",
DataType: "Text",
Cache:false,
Ifmodified:true
});
Original address: http://www.3lian.com/edu/2013/07-29/84622.html
JS Clear IE Browser cache method