41

I need to force the browser to reload the previous page from the server when the user presses the back button.

I've added the following to my response headers:

Cache-Control: no-cache, must-revalidate Expires: -1 

This seems to work for most browsers but not for Google Chrome that insists on returning the cached results.

So does anyone know how I force the browser to get the page from the server when the user presses the back button?

Thank you.

2
  • 1
    If you are interested in stop caching of field contents than take a look at this! Commented Jun 4, 2012 at 12:47
  • 4
    9000 views and the mods call this "an extraordinarily narrow situation". Commented Nov 13, 2012 at 4:15

2 Answers 2

36

as per this bug report in chromium repo, users find that using no-store instead of no-cache will fix it in chrome.

Sign up to request clarification or add additional context in comments.

3 Comments

But what about other browsers. Will adding this break other browsers?
I assume if you use both, you should cover both cases. ie. no-store, no-cache, must-revalidate
In my case with WordPress wp-admin with a plugin I wrote, I couldn't get it to trigger the right header to get around this issue. The fix was that I made my CSS file add a '?time=' . time() on the end. See, in my case, I was making my CSS load a PHP file that generated the image, and it was not running the PHP code for that image until I added the time parameter on the end of the CSS URL.
0

This is not proper, but perhaps you could use the Javascript history object to determine if the current page is the last page in the list? If not, the back button was pressed.

See this reference: http://www.exforsys.com/tutorials/javascript/javascript-history-object-properties-and-methods.html

The real solution of course is to structure your application in such a way that usage of back/forward buttons actually work the way they are supposed to.

3 Comments

I'd not be too happy about implementing this unless there is no other choice, it's a little hacky for my liking. The problem is that page reloading when the user presses back is the way the back button should work. For instance if I was on online banking and I've logged off I don't want people to press back and see my account details. I'd want the page to reload. We've got a similar situation with our application, the information may have changed so we need to reload dynamically.
Yes, it is hackish, and I don't recommend it, unless it is your only option. It's just something I thought of. However, you should remember what those forward and back buttons are for. Websites were originally meant for documents/pages, not applications. While adding no-store as suggested by superfro is a good idea, you should also recommend your users close their browser after logging out, like any other bank or secure site does.
Sorry that did sound abrupt. I appreciate the advice, I'll use it if I don't find a better solution

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.