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