开发者

how can i prevent firefox caching

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="exp开发者_JAVA百科ires" content="0">

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


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);


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?


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);


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜