Javascript:在重定向时清除缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10339567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:32:17  来源:igfitidea点击:

Javascript: Clear cache on redirect

javascriptcachingcookies

提问by Leo Jiang

I can use location.reload(true)to refresh the page and refetch the page. I want to redirect the user to a new URL and clear the cache.

我可以location.reload(true)用来刷新页面并重新获取页面。我想将用户重定向到新 URL 并清除缓存。

More specifically, I have a "Clear all cookies" button that redirects the user to the homepage after being clicked. I want the homepage to be refreshed.

更具体地说,我有一个“清除所有 cookie”按钮,可在用户点击后将其重定向到主页。我想刷新主页。

回答by honyovk

Do something like:

做类似的事情:

var loc = window.location.href; // or a new URL
window.location.href = loc + '?n=' + new Date().getTime(); // random number

EDIT:The only option for reloading static resources (see comment below) would be to append the random number to their URLs server-side by listening for the 'n' query string.

编辑:重新加载静态资源的唯一选项(请参阅下面的评论)是通过侦听“n”查询字符串将随机数附加到服务器端的 URL。

回答by Elliot Bonneville

Sorry, but you can'tclearthe cachewith Javascript.

抱歉,您无法使用 Javascript清除缓存