JS Clear IE Browser cache method

Source: Internet
Author: User
Tags clear browser cache

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
JS automatically clears the IE cache method-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",

JS Clear IE Browser cache method

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.