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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With