QUERY: If-None-Match / ETag caching for Content Pages

General project discussion. NOT for help questions.
Post Reply
martin42
Forum Members
Forum Members
Posts: 126
Joined: Sat Aug 20, 2005 11:35 pm

QUERY: If-None-Match / ETag caching for Content Pages

Post by martin42 »

I've found that this works just fine in Firefox on Content pages, if you add this code to index.php near the bottom (just above the "echo $html" statement):-

Code: Select all

#Do cache-control stuff
if (function_exists('getallheaders'))
        $headers = getallheaders();
else
        $headers = emu_getallheaders();

$hash = md5($html);

#if browser sent etag and it is the same then reply with 304
if (isset($headers['If-None-Match']) && $headers['If-None-Match'] == '"'.$hash.'"')
{
        header('HTTP/1.1 304 Not Modified');
        exit;
}
else
{
        header('ETag: "'.$hash.'"');
};

echo $html;
For non-Apache servers, you also need emu_getallheaders - see earlier thread.

What's puzzling me is that this works just fine for Firefox, but MSIE just doesn't take any notice.  IE just doesn't send the "If-None-Match:" header the second time it fetches a page, even though it all works just fine for style sheets.

Has anyone got content caching to work in IE ?
Post Reply

Return to “General Discussion”