views:

64

answers:

2

I realize that you can't 100% know that this will work in all browsers. All I care about is IE 8, Chrome, and Firefox. I need some base headers that I can put at the top of my PHP pages to allow the Forward/Back buttons to load the cache.

Update: on every page I have a logged in user box at the top of the page which gives the user access to their account.

I'm looking for a performance increase in the web site. The user having to reload the site when clicking back/forward creates unnecessary the server load.

Edit: After extensive research into caching and my level of knowledge I do not know a good solution. It also appears that most others don't know either.

A: 

Are you using sessions? If so, before calling session_start() call session_ cache_ limiter('') .

When you call session_start() the cache limiter is reset to the value set in session.cache_limiter (which by default is 'nocache'). If you want your pages to cache you need to explicitly set the cache limiter to something else first.

You can experiment with other values (see http://www.php.net/manual/en/function.session-cache-limiter.php) but I find session_ cache_ limiter('') gives the best result when trying to, for example, prevent forms from being reset when sending a user back after an error.

Although keep in mind this may open privacy concerns if your pages hold personal data, as personalized pages will become cached.

Rob
+1  A: 

What you want is jumping back in the page cache. There are various variables that determine if a page is put into the page cache.

Surfin' Safari has recently written a blog about the page cache. In short a page isn't put into it if:

  • The page is not completely loaded or uninteresting. (404 errors…)
  • The page is complicated to halt. This is the case if it has Flash elements or movies.
  • The page has frames.
  • The page is secure.
  • The page has an unload event. In their second blog post they write about alternatives.

Those are the rules Webkit follows, I don't know if it's documented for the other browsers. You can never be sure that a page is put into the page cache. It's best to design websites that don't relay on behavior that can change without notice.

Georg