Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop caching in 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?

like image 605
shan Avatar asked Mar 20 '11 13:03

shan


1 Answers

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:

  • Caching tutorial for webauthors and webmasters
  • Making sure a webpage is not cached, across all browsers

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.

like image 164
BalusC Avatar answered Sep 18 '22 15:09

BalusC