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 the Web site cache meta method
Do not cache<meta http-equiv< Span class= "pun" >= "pragma"  Content= " No-cache "> <meta HTTP -equiv= "Cache-control"  Content= "No-cache, must-revalidate" >  <meta http-equiv< Span class= "pun" >= "expires"  Content= "0" Span class= "pun" >>              
Clean up temporary caches of form forms
<body onLoad="javascript:document.yourFormName.reset()">

In fact, the form of the cache for our writing is still helpful, the general situation is not recommended cleaning, but sometimes for security issues, need to clean up!

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. ( "if-modified-since" , " 0 " Xmlhttp. ( "Cache-control" , " No-cache ");  }, Success:function< Span class= "pun" > (response //operation  } Async:false  });             

Method two, directly with Cache:false,

$.Ajax({ Url: ' www.haorooms.com '  Datatype: ' JSON ' , data :{}, Cache:false,< Span class= "PLN" > ifmodified :true , Success:function (response< Span class= "pun") { //operation  }  Async:false });    

method Three: with random number, random number is also a good way to avoid caching!

URL 参数后加上 "?ran=" + Math.random(); //当然这里参数 ran可以任意取了

method Four: use random time, same as random number.

在 URL 参数后加上 "?timestamp=" + new Date().getTime();
Clean up with PHP back-end

Add header ("Cache-control:no-cache, Must-revalidate") to the server and so on (e.g. in PHP)

JS clear the browser cache several ways

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.