Several ways to clear browser caching summary (must SEE) _javascript tips

Source: Internet
Author: User

About Browser Caching

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

Several ways to clean up your Web site cache

Meta method

Do not cache
<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 caching 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 does not recommend cleaning, but sometimes for security issues, need to clean up!

jquery Ajax Clear Browser cache

mode one: use AJAX to request the latest files of the server, plus the request headers if-modified-since and Cache-control, as follows:

$.ajax ({
  URL: ' www.jb51.net ',
  dataType: ' json ',
  data:{},
  beforesend:function (xmlHttp) { 
  Xmlhttp.setrequestheader ("If-modified-since", "0"); 
  Xmlhttp.setrequestheader ("Cache-control", "No-cache");
  },
  success:function (response) {
   //action
  }
  Async:false
 });

method Two, directly using Cache:false,

$.ajax ({
  URL: ' www.jb51.net ',
  dataType: ' json ',
  data:{},
  Cache:false, 
  ifmodified:true,

  success:function (response) {
   //Operation
  }
  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, 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 (); Use PHP back-end cleanup

Header ("Cache-control:no-cache, Must-revalidate") at the service End (""), etc. (as in PHP)

Above this clear browser cache several methods summary (must SEE) is small series share to everybody's content, hoped can give everybody a reference, also hoped that everybody supports the cloud habitat community.

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.