Chapter 15. Rule 13: Configure ETags
Reducing the number of HTTP requests necessary to render your page
is the best way to accelerate the user experience. You can achieve this by
maximizing the browser's ability to cache your components, but the
ETag
header thwarts caching when a web
site is hosted on more than one server. In this chapter, I explain what
ETags are and how their default implementation slows down web
pages.
What's an ETag?
Entity tags (ETags) are a mechanism that web servers and browsers use to validate cached components. Before jumping into the details of ETags, let's review how components are cached and validated.
Expires Header
As the browser downloads components, it stores them in its
cache. On subsequent page views, if the cached component is "fresh,"
the browser reads it from disk and avoids making an HTTP request. A
component is fresh if it hasn't expired, based on the value in the
Expires
header. Let's look at an
example.
When a component is requested, the server of origin has the
option to send an Expires
header
back in the response:
Expires: Thu, 15 Apr 2010 20:00:00 GMT
Chapter 5 recommends
setting an expiration date in the far future. How far is "far" depends
on the component in question. An ad image might have to expire daily,
whereas a company logo could expire in 10 years. The HTTP
specification (http://www.w3.org/protocols/rfc2616/rfc2616-sec14.html#sec14.21)
suggests servers should not set an Expires
date more than one year in the future, but this is ...
Get High Performance Web Sites now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.