Created by Steliyan_Petkov_Georgiev on Feb 10, 2011 in  ->  Programming

How can I make the browser back button request the page from the server again and not take it from the browser cache?

Log in to debate or

@Steliyan_Petkov_Georgiev
0

OK, I figured this out myself. The server needs to send http headers in the response for the desired pageto instruct the browser not to serve it from its cache when the back button is hit but rather make a new request. Here are the proper headers:

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

I first tried with httpServletResponse.setHeader("Cache-Control","no-cache"); but with no success so "no-store" seems to be the correct value for the "Cache-Control" header.
The above is Java code, but the same result could be achieved through other languages too. PHP has a function called header(), e.g.
header("Pragma: no-cache" );
header("Cache-Control: no-store");
header("Expires: 0");

I have test this and it is working OK with Google Chrome, Firefox 3 and IE 8.

on Feb 11, 2011
1 - 1 out of 1