What’s the difference between Expires
and Cache-Control
headers?
According to this Google Developers article, HTTP Caching:
Cache-Control header was defined as part of the HTTP/1.1 specification and supersedes previous headers (e.g. Expires) used to define response caching policies. All modern browsers support Cache-Control, hence that is all we will need.
Heroku devcenter has an excellent article on this subject.
Quoting from it,
While the Cache-Control header turns on client-side caching and sets the max-age of a resource, the Expires header is used to specify a specific point in time the resource is no longer valid.
If you are still interested, I leave this recommendation directly from google's boys. https://developers.google.com/speed/docs/insights/LeverageBrowserCaching They prefer Expires before than Cache-Control
Cache-Control
was introduced in HTTP/1.1 and offers more options than Expires
. They can be used to accomplish the same thing but the data value for Expires
is an HTTP date whereas Cache-Control
max-age lets you specify a relative amount of time so you could specify "X hours after the page was requested".
HTML Cache control is a very similar question and has a good link to a caching tutorial that should answer most of your questions (e.g., http://www.mnot.net/cache_docs/#EXPIRES). To sum up though, Expires
is recommended for static resources like images and Cache-Control
when you need more control over how caching is done.
Except for the private/public options of CC, I can't see any difference. When using Expires like "access plus 1 year/month/week/day", it works in exactly the same way as CC does.
Cache-Control was defined in HTTP/1.1, tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds: Cache-Control: max-age=3600
.
The Expires
header field gives the date/time after which the response is considered stale. The Expires value is an HTTP-date timestamp: Expires: Tue, 18 Jul 2017 16:07:23 GMT
.
If a response includes a Cache-Control
field with the max-age
directive, a recipient MUST ignore the Expires
field.