Max-Age and mod_expires
Before I explain how better caching improves performance, it's
important to mention an alternative to the Expires header. The Cache-Control header was introduced in
HTTP/1.1 to overcome limitations with the Expires header. Because the Expires header uses a specific date, it has
stricter clock synchronization requirements between server and client.
Also, the expiration dates have to be constantly checked, and when that
future date finally arrives, a new date must be provided in the server's
configuration.
Alternatively, Cache-Control
uses the max-age directive to specify
how long a component is cached. It defines the freshness window in
seconds. If less than max-age seconds
have passed since the component was requested, the browser will use the
cached version, thus avoiding an additional HTTP request. A far future
max-age header might set the
freshness window 10 years in the future.
Cache-Control: max-age=315360000
Using Cache-Control with
max-age overcomes the limitations of
Expires, but you still might want an
Expires header for browsers that
don't support HTTP/1.1 (even though this is probably less than 1% of
your traffic). You could specify both response headers, Expires and Cache-Control max-age. If both are present,
the HTTP specification dictates that the max-age directive will override the Expires header. However, if you're
conscientious, you'll still worry about the clock synchronization and
configuration maintenance issues with Expires.
Fortunately, ...