flash service

High_Performance_Web_Sites

Issue link: https://read.uberflip.com/i/1146286

Contents of this Issue

Navigation

Page 44 of 169

Max-Age and mod_expires | 23 This is a far future Expires header, telling the browser that this response won't be stale until April 15, 2010. If this header is returned for an image in a page, the browser uses the cached image on subsequent page views, reducing the number of HTTP requests by one. See Chapter B for a review of the Expires header and HTTP. Max-Age and mod_expires Before I explain how better caching improves performance, it's important to men- tion 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 compo- nent is cached. It defines the freshness window in seconds. If less than max-age sec- onds 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, the mod_expires Apache module (http://httpd.apache.org/docs/2.0/mod/ mod_expires.html) lets you use an Expires header that sets the date in a relative fash- ion similar to max-age. This is done via the ExpiresDefault directive. In this example, the expiration date for images, scripts, and stylesheets is set 10 years from the time of the request: ExpiresDefault "access plus 10 years" The time can be specified in years, months, weeks, days, hours, minutes, or seconds. It sends both an Expires header and a Cache-Control max-age header in the response.

Articles in this issue

Links on this page

Archives of this issue

view archives of flash service - High_Performance_Web_Sites