Content Negotiation and Cache

Content-Negotiation is a scheme which allows a server to serve different documents to different browsers, depending on HTTP headers such as Accept, Accept-Language or others such as User-Agent. Unfortunately, in HTTP 1.0 (the current transport protocol), this does not work properly with cache agents. Either the negotiated documents are not cacheable, which consumes global bandwidth and results in the pages being slower to load, or it is possible for a user to receive cached pages with the wrong attributes (in the wrong language, for instance).

The next revision of the transport protocol, HTTP 1.1, addresses many of these problems and introduces new HTTP headers allowing cache agents to serve negotiated documents. Meanwhile, one way around the problem is to negotiate redirected documents. In this way, a small transfer is made to the origin server, which then returns the URL of a cacheable document with the required characteristics.

This Perl script (select_lang) is an example of how this may be done. It selects a document based on the value of the Accept-Language header. The easiest implementation relies on the Action and AddHandler directives in Apache. For instance, one might install select_lang in cgi-bin, then use the directives

AddHandler select_lang lang
Action select_lang /cgi-bin/select_lang
which will invoke the script on any file with a suffix of .lang, e.g. http://some.org/somewhere/some.lang
Alternatively, the script may be given explicitly: http://some.org/cgi-bin/select_lang/somewhere/some.lang

Given a URL such as .../some.lang, and an HTTP Accept-Language header such as en_US,fr,de , the script will search for some.en_us.html (US English), some.en.html (English), some.fr.html (French), some.de.html (German), defaulting to some.html. some.lang must exist, though it may be of zero length.
Here it is in action.

If the size of the various HTML files is fairly small (a few kb), it may be easier to make the document itself content-negotiable, which will involve one trasfer from the origin server, instead of one from the origin (a redirect), and one from cache.

[Cache Now!]

Vancouver Webpages