JS clear the browser cache several ways

Source: Internet
Author: User
Tags browser cache website performance

About Browser Caching

Browser cache, sometimes we need him, because he can improve website performance and browser speed, improve website performance. But sometimes we have to clear the cache, because the cache can be bad and there are some wrong data. such as stock site real-time updates, such as the site is not cached, like some sites are rarely updated, there is a cache or better. Here are a few ways to clear the cache today.

Several ways to clean up your Web site cache

Meta method

//不缓存 < META HTTP-EQUIV = "pragma" CONTENT = "no-cache" > < META HTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, must-revalidate" > < META HTTP-EQUIV = "expires" CONTENT = "0" >

Clean up temporary caches of form forms

<body onLoad="javascript:document.yourFormName.reset()">

jquery Ajax clears the browser cache

Method One: Use Ajax to request the latest server files, and add the request headers If-modified-since and Cache-control, as follows:

$.ajax({    url: ‘www.haorooms.com‘ ,    dataType: ‘json‘ ,    data:{},    beforeSend : function (xmlHttp){     xmlHttp.setRequestHeader( "If-Modified-Since" , "0" );     xmlHttp.setRequestHeader( "Cache-Control" , "no-cache" );    },    success: function (response){      //操作    }    async: false }); method Two, directly with Cache:false, $.ajax({    url: ‘www.haorooms.com‘ ,    dataType: ‘json‘ ,    data:{},    cache: false ,    ifModified : true ,    success: function (response){      //操作    }    async: false });

Method Three: With random number, random number is also a good way to avoid caching!

URL parameter Plus "? ran=" + math.random (); Of course here the parameter ran can be arbitrarily taken

Method Four: Use random time, same as random number.

After the URL parameter, add "? timestamp=" + New Date (). GetTime ();

Clean up with PHP back-end

Add header to the server ("Cache-control:no-cache, Must-revalidate")

Method Five:

window.location.replace("WebForm1.aspx");  

The parameter is the page you want to overwrite, and replace replaces the page specified by the Replace parameter with the current page.

A.html

The following is a reference fragment:

< html >     < head >       < title >a</ title >         < script language = "javascript" >         function jump(){           window.location.replace("b.html");         }       </ script >     </ head >     < body >      < a href = "javascript:jump()" rel = "external nofollow" rel = "external nofollow" >b</ a >    </ body > </ html >

B.html

The following is a reference fragment:

< html >     < head >       < title >b</ title >         < script language = "javascript" >         function jump(){           window.location.replace("a.html");         }       </ script >     </ head >     < body >      < a href = "javascript:jump()" rel = "external nofollow" rel = "external nofollow" >a</ a >    </ body > </ html >Original link: https://www.jb51.net/article/108541.htm

JS clear the browser cache several ways

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.