Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari not sending "If-Modified-Since" and "If-None-Match" headers

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!

like image 381
basbebe Avatar asked Dec 09 '12 17:12

basbebe


People also ask

What are the If-modified-since and if-none-match header used for?

The If-Modified-Since header is used to specify the time at which the browser last received the requested resource. The If-None-Match header is used to specify the entity tag that the server issued with the requested resource when it was last received.

What does the if-none-match header do?

The If-None-Match HTTP request header makes the request conditional. For GET and HEAD methods, the server will return the requested resource, with a 200 status, only if it doesn't have an ETag matching the given ones.

Why if-modified-since header line is used in Web caching?

What does the If-Modified-Since header do? # The If-Modified-Since HTTP header indicates the time for which a browser first downloaded a resource from the server. This helps determine whether or not the resource has changed since the last time it was accessed.

What is if-modified-since header?

The If-Modified-Since request HTTP header makes the request conditional: the server sends back the requested resource, with a 200 status, only if it has been last modified after the given date.


1 Answers

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.

like image 145
Chris Wesseling Avatar answered Oct 11 '22 18:10

Chris Wesseling