We had an interesting question a while back on cache control:
I’m considering using CacheRight to improve the efficiency of my web site but one of the other options I’m looking at is the use of etags to improve performance. Much of my initial information on etags is based on the following article http://www.desalvo.org/blog/index.php?p=230 but I would be interested to know what you think about etags. It appears to me that implementing etags will involve some work and I would prefer to just license CacheRight if I’m going to end up in the same place.
Hmmmph. Good question.
ETags (or e-tags, depending on who’s typing) can be an effective way to manage the caching of certain files, especially ones that -- as the author alludes to -- are dynamically generated making the Last-Modified value unreliable. The ETag and its use are described in the most recent HTTP specification, but in practice it has not yet been widely utilized. It's too bad, but generally adoption of these things can take a while (and it is gaining momentum out there…).
CacheRight uses some of the more widely used expiration cache related alternatives to the ETag, namely the Expires header and the Cache-control header. By setting an expiry time for the files on your Web site, you can go even farther than merely relying on the conditional GET and the 304 response that a server sends when a file has not changed; you can prevent the contact with the server from happening at all. If a browser receives an image with the cache control headers that say the image can be considered fresh for 2 weeks, then for 2 weeks the image can be pulled directly from the browser's (or proxy's) cache on subsequent requests. This is noticeably faster than even a conditional GET and a 304 response from the server since there is no round trip. After two weeks, a conditional GET would be sent to the server to check the Last-Modified date, then again, no requests would be made for the duration of the specified freshness period.
So, briefly, the cache control mechanism that CacheRight uses is more widely used than the ETag, it requires no coding changes to your existing Web pages, and it works to avoid the unnecessary requests and connections to your Web server for files that do not need to be re-requested with each visit. Part of the rationale behind ETags is to provide sub-one second resolution in validating cached entities, where Last-Modified are limited to one second resolution. The ETag certainly has its uses, but it serves more as an alternative to the Last-Modified value rather than an expiry-based caching mechanism.
Happy weekends,
Port80