Several ways to clear the browser cache

Source: Internet
Author: User
Tags browser cache clear browser cache
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" 
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.haorooms.com ',
     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.haorooms.com ',
     dataType: ' json ',
     data:{},
     Cache:false, 
     ifmodified: True,

     success:function (response) {
         //Operation
     }
     async:false
  });

method Three: 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.

use PHP back-end cleanup

Header ("Cache-control:no-cache, Must-revalidate") at the service End (""), etc. (as in PHP)
C # httpclient prohibit caching
           using (var client = new HttpClient ())
            {
                //Method 1: 
                cachecontrolheadervalue CacheControl = new Cachecontrolheadervalue ();
                Cachecontrol.nocache = true;
                Cachecontrol.nostore = true;
                Client. Defaultrequestheaders.cachecontrol = CacheControl;

                Method 2: 
                //client. Defaultrequestheaders.add ("Cache-control", "No-cache");
                Try
                {
                    client. Getstringasync (URL);
                    return true;
                }
                Catch
                {return
                    false;
                }
            }
C # page cleanup cache
        private void Setpagenocache () 
        {

            Response.Buffer = true;

            Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds ( -1);

            Response.Expires = 0;

            Response.CacheControl = "No-cache";

            Response.AddHeader ("Pragma", "No-cache");

        }

Any sentence can be:

    (1)     Response.Buffer = true; 
            Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds ( -1);

            Response.Expires = 0;

            Response.CacheControl = "No-cache";

            Response.AddHeader ("Pragma", "No-cache");

    (2) HTML method

        <meta http-equiv= "Pragma" content= "No-cache" > <meta http-equiv= "Cache-control"

Content= "No-cache" >

<meta http-equiv= "Expires" content= "0" >

    (3) when the original page is called again, pass a parameter to the page:    href = "****.aspx?random ()"

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.