Browsers seem to be ignoring my cache control Python response headers

594 Views Asked by At

I'm currently developing an app on google-app-engine using webapp2 Python. I'm developing on a Mac, Lion, and testing in Firefox 26, Safari 6.02 and Google Chrome.

I have a home page with login button. You click login I AJAX the form to the server, on success I use a window.location.replace to reload the home page minus login button and provide access to user pages. On logout I AJAX a call to a handler on the server, dump the session and on success use another window.location.replace to reload the home page with login button.

However, if I go back or forward, depending, pages from the user activity show up. These pages are not loaded via AJAX, they are all either loaded as redirects from the server or as window.location.href from the client.

I am having problems on localhost with Firefox bfcache. Now I have set my Python headers in my dispatch method to:

    self.response.headers["Pragma"]="no-cache"
    self.response.headers["Cache-Control"]="no-cache, no-store, must-revalidate, pre-check=0, post-check=0"
    self.response.headers["Expires"]="Thu, 01 Dec 1994 16:00:00"
    self.response.headers['Cache-Control'] = 'public, max-age=0'

And when I check the Net console in Firebug, the expiration date is 1970 sometime.

However, bfcache seems to freeze the page as per its specs and not respect the expiration and reload the page when clicking the back forward buttons.

Is this because I am on localhost or using http for testing? I really am confused with this whole bfcache thing. I understand that I can use onpageshow event in the browser to do something with this client side, but I would rather sort this server side if possible.

I have all the necessary controls for direction on the server calls, so if you refresh any of these pages they will redirect you to the logged out home page, but I just can't seem to manage to force these pages to refresh.

0

There are 0 best solutions below