Sam YC
Sam YC

Reputation: 11637

last-modified vs expires precedence

I have read through lot of discussions, and found most of the claim saying expires is higher precedence over last-modified, meaning if a response already expired, it will not even send out if-modified-since to server and of course the response code will not be 304.

But my situation is totally weird, I have returned back last-modified in response, and somehow CDN/proxy side add in expires header, which value is same as date response header, I suppose same value in expires and date header will cause the response stale immediately, but in fact, my client browser will still send out request with if-modified-since header, this will cause a 304 response code returned from the server.

I read throught RFC 2616, it doesn't tell much as well. So what happen to this case?

Upvotes: 2

Views: 517

Answers (1)

Sam YC
Sam YC

Reputation: 11637

Almost 2 years but find no answer...

I managed find out some reference:

The freshness lifetime is calculated based on several headers. If a "Cache-control: max-age=N" header is specified, then the freshness lifetime is equal to N. If this header is not present, which is very often the case, it is checked if an Expires header is present. If an Expires header exists, then its value minus the value of the Date header determines the freshness lifetime. Finally, if neither header is present, look for a Last-Modified header. If this header is present, then the cache's freshness lifetime is equal to the value of the Date header minus the value of the Last-modified header divided by 10.

Although I can't find confirmed precedence in RFC, but I think this MDN quote is quite reliable enough.

It is pretty normal if some browser doesn't implement in this way... So to avoid any issue, the best is to not return these two headers in the response at the same time.

Upvotes: 2

Related Questions