Question

I'm generating dynamic content with PHP.

I'm sending the following HTTP-header:

HTTP/1.1 304 Not Modified
Date: Sun, 09 Dec 2012 17:24:41 GMT
Server: Apache
Connection: keep-alive, Keep-Alive
Keep-Alive: timeout=1, max=100
Etag: "237f43b800e655dbe6567f7d32d34c99"
Expires: Sun, 16 Dec 2012 17:24:41 GMT
Cache-Control: max-age=604800
Vary: Accept-Encoding

I later check for the Etag to send a header('HTTP/1.1 304 Not Modified') if it matches. This works perfectly with Chrome and Firefox. However, Safari (Version 6.0.2) does not send "If-Modified-Since" and "If-None-Match" headers. This is the Request-Header sent by Safari on the second page hit:

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Cache-Control: max-age=0

All other files linked on that page receive the right Request-Headers and Safari used cached files or 304 where appropriate.

Why doesn't send Safari the correct Request-Header? What could I change?

Thank you!

Was it helpful?

Solution

If-Modified-Since

The notes of If-Modified-Since warn against using something different than the contents of the Last-Modified response header:

Note: If a client uses an arbitrary date in the If-Modified-Since header instead of a date taken from the Last-Modified header for the same request, the client should be aware of the fact that this date is interpreted in the server's understanding of time.

Your response doesn't contain a Last-Modified, but even if it did, nothing in the spec says that user agents MUST or SHOULD send If-Modified-Since, they just MAY.

If-None-Match

As to why Safari doesn't send an If-None-Match beats me; your ETag looks valid.

Enforcing Caching in general

Again in general nothing in the spec says you MUST cache, just that when you do, you MUST obey Cache-Control. So it's a bit of an asymmetric relation, you can enforce (transparent) caches to recheck with the origin server, but as an origin server, you can't enforce useragents to cache.

What can I do about it?

Safari is only partly free software. So nothing much, if adding a Last-Modified doesn't help.

OTHER TIPS

I ended up solving this one by looking for what headers are sent by various big sites, and have ended up with

Last-Modified: {some date}
Cache-Control: max-age=0, must-revalidate
Expires: -1

This is working on Safari for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top