问题
I need the client (using javascript) to invalidate a page it has and essentially fetch a new version?
I thought I could do it all with headers: Invalidating cached content, If-Modified Headers?
If there NO way to have the browser refresh its current cached version, with out making a new request (via a new URL) ... so that the same original URL request could be used to see the updated content?
回答1:
You can't do that with javascript, to solve your problem or use method POST instead of GET or use nocache random parameter trick:
If you want more information, see: Is it possible to cache POST methods in HTTP?
回答2:
If you want to reload the current page you can do:
location.reload(true);
Otherwise the "traditional" way is to add a random querystring onto the end
'...?rnd=' + Math.random();
回答3:
When you reference the page, add a random variable on to the end. For instance:
document.location.href = 'mypage.html?randomVar=454068934';
That will ensure a non cached version. I recommend using javascript generated guids.
回答4:
what I did is pass a random parameter in the url. ie if I need to fetch products.php I call it with products.php?rand=23443545. This way the cache doesn't interfere.
来源:https://stackoverflow.com/questions/1301922/how-can-i-invalidate-a-page-in-the-browser-cache-from-the-client-side