停止 Firefox 中的缓存
我正在使用以下代码。
<%
response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0 ");
response.addDateHeader ("Expires", 0);
%>
它在 IE 中完美运行,但该页面在 Firefox 中仍然被缓存。我也想停止 Firefox 中的缓存。有什么建议吗?
I am using following code.
<%
response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0 ");
response.addDateHeader ("Expires", 0);
%>
It works perfectly in IE, but the page is still cached in Firefox. I want to stop caching in Firefox as well. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您混淆了
Cache-Control
和Pragma
标头。交换它们。也就是说,Firefox 还需要no-store
和must-revalidate
以及no-cache
。更重要的是,只有
no-cache,no-store,must-revalidate
就足以让Cache-Control
跨浏览器工作。另请参阅:
与具体问题无关,我'建议将这段代码放在映射到
*.jsp
上的Filter
类中,而不是将相同的代码复制粘贴到您想要的所有 JSP 文件上禁用浏览器缓存。You're confusing
Cache-Control
andPragma
headers. Swap them. Firefox namely also requiresno-store
andmust-revalidate
along theno-cache
.Even more, only the
no-cache,no-store,must-revalidate
has been enough forCache-Control
to get it to work across browsers.See also:
Unrelated to the concrete problem, I'd recommend to put this piece of code in a
Filter
class which you map on*.jsp
instead of copypasting the same code over all JSP files for which you'd like to disable the browser cache.