JavaRanch Home    
 
This page:         last edited 12 August 2011         What's Changed?         Edit

No Cache Headers   

While the browsers usually have a mind of their own, the following hints added to the response header seem to prevent most modern browsers from pulling pages out of cache when the same URL is "hit".

   response.setHeader( "Pragma", "no-cache" );
   response.setHeader( "Cache-Control", "no-cache" );
   response.setDateHeader( "Expires", 0 );

The same effect can be achieved by using meta tags in the HTML header:

 <meta http-equiv="Pragma" content="no-cache">
 <meta http-equiv="Cache-Control" content="no-cache">
 <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">

The Cache-Control header was added in HTTP 1.1, while the other two were also present in HTTP 1.0.

Note that it's easy to avoid having to put this onto each and every page (or servlet) by creating a servlet filter that adds the appropriate headers to the response for each request to a non-static resource.



Back to:

ServletsFaq

JspFaq


JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton