Expires vs max-age, which one takes priority if both are declared in a HTTP response?
Asked Answered
C

2

52

If a HTTP response that returns both Expires and max-age indications which one is used?

Cache-Control: max-age=3600
Expires: Tue, 15 May 2008 07:19:00 GMT

Considering that each one refers to a different point in time.

Chlorinate answered 25/9, 2011 at 22:56 Comment(1)
How the browser cache will clear in this scenario? Will it request to cloudflare again according to max-age ?Pleonasm
F
59

See this answer:

Difference between three .htaccess expire rules

If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive. This rule allows an origin server to provide, for a given response, a longer expiration time to an HTTP/1.1 (or later) cache than to an HTTP/1.0 cache. This might be useful if certain HTTP/1.0 caches improperly calculate ages or expiration times, perhaps due to desynchronized clocks.

Fetich answered 26/9, 2011 at 0:23 Comment(2)
Is it that only in Apache or it is a general rule? Thanks.Chlorinate
This applies in general; the paragraph above comes from section 14.9.3 of the HTTP/1.1 specification.Fetich
A
14

This case is explained in the official RFC on W3C.

The max-age directive takes priority over Expires

Accoutre answered 6/12, 2013 at 8:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.