5

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?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
shan
  • 53
  • 1
  • 3

1 Answers1

10

You're confusing Cache-Control and Pragma headers. Swap them. Firefox namely also requires no-store and must-revalidate along the no-cache.

response.addHeader("Cache-Control", "no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0"); 
response.addHeader("Pragma", "no-cache"); 
response.addDateHeader ("Expires", 0);

Even more, only the no-cache,no-store,must-revalidate has been enough for Cache-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.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452