How can I invalidate a page in the browser cache f

2019-06-28 04:53发布

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?

4条回答
贪生不怕死
2楼-- · 2019-06-28 05:19

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();
查看更多
▲ chillily
3楼-- · 2019-06-28 05:21

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.

查看更多
Ridiculous、
4楼-- · 2019-06-28 05:23

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?

查看更多
聊天终结者
5楼-- · 2019-06-28 05:23

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.

查看更多
登录 后发表回答