Header
is a directive of mod_headers that allows to modify HTTP header fields. In this case Header set
effectively sets the mentioned header fields Cache-Control and Expires, so an already existing header field will be overwritten.
The first directive sets the header field Cache-Control with the value max-age=290304000
, that describes the freshness lifetime to be 290304000 seconds relative to the response time.
In contrast to that, the second directive sets the header field Expires with the value Thu, 15 Apr 2020 20:00:00 GMT
that describes the freshness lifetime with an absolute time value.
Both Cache-Control’s max-age value and Expires expiration time stamp can be transformed to the other:
The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply:
freshness_lifetime = max_age_value
Otherwise, if Expires is present in the response, the calculation is:
freshness_lifetime = expires_value - date_value
But if both are present, Cache-Control’s max-age is preferred over Expires:
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.
In opposite to setting these HTTP caching control header fields manually, mod_expires ExpiresDefault
directive allows an easy setup for HTTP caching. The freshness lifetime can either be described with an absolute value or with a relative value, either relative to the response time (i.e. access
/now
) or relative to the modification time of the requested file (i.e. modification
). It uses both Cache-Control and Expires.
In this case the third directive sets the default freshness lifetime to be 10 years from the time of response on.
I would use mod_expires for HTTP cache control instead of doing it manually with Header
. It is far more convenient, allows both relative and absolute freshness times and uses both Cache-Control and Expires.