how can i prevent firefox caching

rdn picture rdn · Jun 24, 2011 · Viewed 6.9k times · Source

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.

Answer

Brad picture Brad · Jun 24, 2011

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