To be honest, all the web applications I've written so far have always disabled page caching. But even though this application has multiple users that access the same data concurrently, they business owners wanted to turn on page caching. I agree that the back button warning from IE is really annoying, but I let them know some of the issues that go along with caching, and we agreed to give it a try.
After playing around a bit, we figured the behavior we wanted was that any page forward movement (form submit or link click) should get a new page from the server, while the back and forward buttons should use the browser's cache (to avoid the annoying message from the brwoser). There was one catch, they wanted the cache to expire after a set amount of time. I couldn't figure it out. Is there some setting I'm missing? The only way to make the back button cache, and link clicking not cache is to use the browser's detault behavoir. But then the duration of the cache is control usually be disk space, set on the browser.
I constructed the table below to document the behavoir of IE vs. Mozilla with the different caching methods. The three methods I tried were:
-Default Caching (DC)- This is what ever the browser does by default. No special headers were sent.
-Caching Disabled (CD)- The following headers were sent:
response.setHeader( "Cache-Control", "no-cache" );
response.setDateHeader( "Expires", -1 );
response.setHeader( "Pragma", "No-cache" );
-Some Caching (SC)- Pages are only active for a set amount of time, in this case one minute. The following headers were sent:
response.setHeader( "Cache-Control", "max-age=" + (1*60) +", must-revalidate" );
Browser/Caching | Form Post | Form Get | Link | Back | Forward | Reload |
---|---|---|---|---|---|---|
IE - DC | - | - | - | X | X | X |
IE - CD | - | - | - | - | - | - |
IE - SC | - | -(?) | X | X | X | X |
Moz - DC | - | - | - | X | X | X |
Moz - CD | - | - | - | - | - | - |
Moz - SC | - | X | X | X | X | X |
(X indicated page was retrieved from cache, not the server)
(? Strange but true. IE treats a form GET different than a link GET)
This is the page I used to test things:
<%@ page import="java.util.Date"%>
<%
/*
response.setHeader( "Cache-Control", "no-cache" );
response.setDateHeader( "Expires", -1 );
response.setHeader( "Pragma", "No-cache" );
*/
//response.setHeader( "Cache-Control", "max-age=" + (1*60) +", must-revalidate" );
%>
Time: <%= System.currentTimeMillis() %> <%= new Date()%> <br />
<form taget="/commsales/cache-test.jsp" method="post">
Foo: <input type="text" name="foo" /><br />
<input type="submit" value="Submit Post" />
</form>
<form taget="/commsales/cache-test.jsp" method="get">
Bar: <input type="text" name="bar" /><br />
<input type="submit" value="Submit Get" />
</form>
<a href="/commsales/cache-test.jsp">Link</a>
<< Home