Html 如何阻止 chrome 缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4146813/
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-08-29 05:11:44  来源:igfitidea点击:

How to stop chrome from caching

htmlgoogle-chromereloadmeta-tags

提问by Craig Norton

I need to force the browser to reload the previous page from the server when the user presses the back button.

当用户按下后退按钮时,我需要强制浏览器从服务器重新加载上一页。

I've added the following to my response headers:

我已将以下内容添加到我的响应标头中:

Cache-Control: no-cache, must-revalidate
Expires: -1

This seems to work for most browsers but not for Google Chrome that insists on returning the cached results.

这似乎适用于大多数浏览器,但不适用于坚持返回缓存结果的谷歌浏览器。

So does anyone know how I force the browser to get the page from the server when the user presses the back button?

那么有谁知道当用户按下后退按钮时我如何强制浏览器从服务器获取页面?

Thank you.

谢谢你。

采纳答案by superfro

as per this bug reportin chromium repo, users find that using no-store instead of no-cache will fix it in chrome.

根据chrome repo 中的这个错误报告,用户发现使用no-store 而不是no-cache 将在chrome 中修复它。

回答by Brad

This is not proper, but perhaps you could use the Javascript history object to determine if the current page is the last page in the list? If not, the back button was pressed.

这是不正确的,但也许您可以使用 Javascript 历史记录对象来确定当前页面是否是列表中的最后一页?如果没有,则按下后退按钮。

See this reference: http://www.exforsys.com/tutorials/javascript/javascript-history-object-properties-and-methods.html

请参阅此参考:http: //www.exforsys.com/tutorials/javascript/javascript-history-object-properties-and-methods.html

The real solution of course is to structure your application in such a way that usage of back/forward buttons actually work the way they are supposed to.

真正的解决方案当然是以这样一种方式构建您的应用程序,即后退/前进按钮的使用实际上按照它们应该的方式工作。