1 (edited by sleddog 2004-04-17 03:49)

Topic: Regarding cache headers

I've noticed that several recent BB releases (including punBB) are setting a series of no-cache headers. For punBB these are set in headers.php and consist of:

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT');
header('Pragma: no-cache');

The result is that when using the "Back" or "Forward" functions in a web browser, the browser will re-fetch a page from the web rather than load it from cache. I realize that this is personal preference, but for me this is a PITA. I'm on either a low-bandwidth dialup or a high-latency satellite connection, and this re-fetching make navigating a BB really slow. (VB3, with it's many graphics, is a particular nightmare.)

I've experimented a bit with these no-cache headers and found that just one of them causing this re-fetching on Back or Forward. I've disabled it on my punBB at http://www.labradorstraits.net/forum/ :

//header('Cache-Control: no-store, no-cache, must-revalidate');

The purpose of no-cache headers is to ensure that the reader sees most recent content. However, I would argue that re-fetching a page on Back or Forward is wrong, as that is not the intent of these functions. When I hit "Back" I want to go back to exactly what I was looking at previously, not "back" to a now-revised copy of that page.

New post markers and cookie updating work just fine on my board with the above cache header disabled. And I can flip back and forth between pages without re-fetching from the web each time.

I'd be interested to hear any comments others may have on this.

Re: Regarding cache headers

I'm glad someone brought this up. I must admit my knowledge of the Cache-Control headers is severely limited. You say you don't experience any problems when removing that header. What browser are you using? IE and Mozilla usually work fine either way, but Opera is a bit more tricky.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Regarding cache headers

Opera will always ignore the "Cache-Control: no-store, no-cache, must-revalidate" headers on back & forward. It'll load the requested page immediately from memory cache. There is no way I know of to change that (smart design I'd say!) Of course it honours those headers when a page is re-requested, say by clicking a link or loading a bookmark. This is the way it should be (IMO).

Mozilla and IE 5 & 6 will check/re-fetch on back/forward. I haven't had an opportunity to check with other browsers.

Re: Regarding cache headers

So, what you're saying is that "Cache-Control: no-store, no-cache, must-revalidate" is useless? As I said before, my knowledge of the HTTP caching mechanism is very limited. I'm just asking becuase most forums I know of do send those headers.

The problem I remember having with Opera was that when you were redirected via a HTML meta tag (i.e. <meta http-equiv="refresh" content="1;URL=blaha.php">) you would get a cached page. This happened when logging in. You would get redirected to the index page (or whatever page you were on) and you would still appear to be a guest until you refreshed the page.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

5 (edited by sleddog 2004-04-18 02:21)

Re: Regarding cache headers

No, I'm not saying those headers are useless. Quite the opposite; they are extremely effective. What I'm saying is that (again, my opinion) browsers should ignore these headers when going Back/Forward. But mainstream browsers IE and Mozilla don't ignore them.

Example:

1. I visit http://punbb.org/forums/index.php
2. I click the link for "Pun discussions" and go to http://punbb.org/forums/viewforum.php?id=40
3. If at this point I click the link "Home" to re-visit http://punbb.org/forums/index.php then yes, the cache headers should cause the page to be re-checked and re-fetched. But if I simply click my Back button, then the page should not be re-fetched -- but it is.

The other four header lines in header.php are quite sufficient to ensure that people are not getting stale pages:

header('Cache-Control: post-check=0, pre-check=0', false);
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT');
header('Pragma: no-cache');

None of these headers interfere with "normal" navigation using the browsers Back and Forward.

Opera's caching options are different from IE and Mozilla. Instead of "automatic" or "per session" settings, cache settings are based on time (5 minutes, an hour, 5 days, etc.) Alternatively you can opt for "always", which is what I do. This doesn't mean that pages are always re-fetched, it means that pages are always checked for changes. Only if the server reports change is the page re-fetched, otherwise it s loaded from cache.

I have a login on my website with a meta-refresh page and it works fine with Opera set like this. Not with Netscape 4 though, but that's another story, best forgotten smile

In a nutshell, I think "header('Cache-Control: no-store, no-cache, must-revalidate')" serves no useful purpose (when bundled with the other cache-limiting headers), and in fact hinders browsing for people on low bandwidth / high latency connections.

Re: Regarding cache headers

Ok, cool. Thanks for clearing that up for me. I will try commenting out the header call in these forums and we'll see what happens.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Regarding cache headers

So much faster smile

We'll see if there's any reaction from other users here.

8

Re: Regarding cache headers

Will this impact in any way where pages are cached remotely e.g. AOL users? I thought I read somewhere that AOL users would be forced to manually reload the page after the login redirect but that could be out of date information.