how can i prevent firefox caching

拟墨画扇 提交于 2019-12-12 17:19:25

问题


i tried a lot of possible solutions but i can't solve the problem:

<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="no-store">
<meta http-equiv="Cache-control" content="must-revalidate">
<meta http-equiv="pragma" content="no-cache"> 
<meta name="expires" content="0">

these are not working. Can anybody help? I am using jsp/servlet. And application is a portlet for websphere portal 6.1.


回答1:


The meta headers are only used when the page is requested from the local disk file system instead of over HTTP. You need to set the real HTTP response headers instead.

Create a filter which does basically the following job:

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse hsr = (HttpServletResponse) res;
    hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    hsr.setDateHeader("Expires", 0); // Proxies.
    chain.doFilter(req, res);
}

Map it on an URL pattern of for example *.jsp to get it to run on all JSP pages.

You had it right with the Cache-Control headers in your original question, it's mandatory to have no-store and must-revalidate along no-cache. Almost all other answers posted as far are basically MSIE targeted.

See also:

  • How to control web page caching, across all browsers?



回答2:


Never rely on meta tags in an HTML page to control caching. Instead you need to set the HTTP headers in your response. In your controller before you display any output you will want to set the following:

response.setHeader("Cache-Control", "max-age=0, must-revalidate");

This has worked for me in the past but you may also like to try the following if that doesn't do the trick

response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 1);



回答3:


Try setting those in the response header in your servlet like,

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);



回答4:


Firefox 3 is known for it's cache problems

https://bugzilla.mozilla.org/buglist.cgi?quicksearch=Cache-control

I once implemented a solution where every page would get a random ID added to it's name, so Firefox thinks it's a different page. Don't know much about portlets, but have you tried that?




回答5:


we had similar problems with Liferay Portal Server. Our solution was to add a timestamp to the link of the resources (css/js), something like

/mysite/css/menu.css?t=1291218768531

We control when we refresh the timestamp from within our application, so we have control when we force the browser to reload the resource.



来源:https://stackoverflow.com/questions/6467451/how-can-i-prevent-firefox-caching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!