Using and understanding the 304 Not Modified HTTP Header with the PHP Smarty templating system
Sponsored Links:
Smarty Caching & 304 Not Modified HTTP Header
The HTTP 1.1 specification introduced two HTTP headers for identifying content which hasn’t changed since a client’s last request. These are the Last-Modified and Etag headers. In both cases, the client can ask for the item conditionally. If either the Etag has changed or the item has changed since the date specified in Last-Modified. If the item has not changed the server returns 304 Not Modifed, and the client can use it’s local cached copy. This saves bandwidth and server load for the website and makes page requests faster for the client.
Smarty has built in support for the 304 Not Modifed HTTP header for cached pages. To turn on this feature set the class variable $cache_modified_check to true
$smarty->cache_modified_check = true;
Note this does not work for pages in which you’ve already called session_start() if the php configuration directive session.cache-limiter is set to anything other than none
In the default configuration, when you call session_start(), PHP sends out 3 headers:
Set-Cookie: PHPSESSID=288b599e09eece3ba962e3f29cf0913a; path=/ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache
To enable pages which require session support and which can be cached, call session_modified_limiter(“none”); before calling session_start().