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 ()"