Daniel Crichton wrote:
> Daniel wrote on Mon, 09 Mar 2009 13:40:31 +0100:
>> I'm feeding some image files through PHP, setting headers
>> programatically for caching. For FF I found that setting cache control
>> to "public" and providing a last modified time will make the browser
>> provide an if-modified-since header on subsequent requests on the same
>> image file.
>> This, however, does not apply to IE (7, not sure about v6). I'm
>> wondering what headers I have to provide to make IE include the
>> if-modified-since header when it returns?
>> Here's an example of the headers provided with each image that is
>> served by my code:
>> Date Mon, 09 Mar 2009 12:30:31 GMT
>> Server Apache/2.2.3 (Debian) mod_fastcgi/2.4.2
>> PHP/5.2.0-8+etch11 mod_perl/2.0.2 Perl/v5.8.8
>> Vary Host
>> X-Powered-By PHP/5.2.0-8+etch11
>> Cache-Control public
>> Last-Modified Mon, 09 Mar 2009 12:30:31 GMT
>> Expires 600
>> Content-Length 283
>> Keep-Alive timeout=15, max=92
>> Connection Keep-Alive
>> Content-Type image/gif ------------------------
>> Only some of these are specifically defined by me (Cache-Control, Last-
>> Modified, Expires, and Content-Type), the rest are courtesy of
Hi Daniel, thanks for your reply (and for having such a pretty name, hehe)!
> You should only require a Last-Modified header, and that should cause IE
By "require" you mean I should just provide it, right? I found that to make
Firefox and Konqueror provide the if-modified-since header I had to provide
last-modified, and the cache-control: public headers.
> after the initial request to then send If-Modified-Since headers in
> subsequent requests for the same URL. You may need to drop the
> Cache-Control: public header.
> I'm assuming that the above isn't the actual headers returned by your PHP
> as it's missing the : between name and value and the white space shouldn't
> be there.
You assume right, it's copy/pasted from firebug, so it's everything that's
actually delivered to the client browser, not just what I set.
In the meantime, however, I've read some more on IE7, and it seems that
(sometimes?) it prefers to provide the if-none-match header rather than if-
modified-since. In any effect, this is the behavior I'm experiencing.
Now, if I provide an etag header, IE7 will provide an if-none-match header
on the next request, and if I use a timestamp as etag, I can determine the
age of the browser's cached item, and decide whether to send a 304 or
deliver the content. So basically I'm good there
However, I haven't gotten rid of the symptom that started me on this, which
is the fact that mouseover effects continue to flicker, since IE asks the
server if there's any new content on each mouse over or out event, even
though I believe I told it that the content I provided it with should be
good for ten minutes. Maybe you have a tip? Here are the headers I'm
providing ATM, please forgive the PHP syntax:
$retrieved_time = (int)$_SERVER['HTTP_IF_NONE_MATCH'];
$retrieved_time = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$now = time();
// We ask browsers to cache static content for 10 minutes:
if ($retrieved_time+600 < $now)
// We need to set a public cache control and put a "last modified" header,
otherwise we don't
// receive the "if modified since" header on subsequent re-requests:
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $now).' GMT');
header('HTTP/1.1 304 Not Modified');