Edge Side Includes

Edge Side Includes (ESI) is an XML-based language (and a W3C standard) that allows web page and template developers to include caching requirements in their page mark-up. This makes it possible to establish a differential caching policy that caches different parts of a page for different lengths of time. A page is essentially broken up into fragments with different caching policies. Some highly dynamic fragments (the number of messages in a user's inbox, for example) may be cached for a very short time or not at all, while parts that are likely to change less often (such as a news article or blog entry) can be cached for much longer. Big IP, Varnish, Akamai, Oracle Web Cache and Squid 3 all support ESI.

The basic idea is that the application developer, who is the person best placed to know how long a given fragment should be cached, sends that information to the cache server in the form of ESI directives. With Varnish at least, no additional configuration is required to make the cache server respect ESI directives. This example shows how to set a cache time of one minute on a fragment.

<%@ taglib uri="http://jakarta.apache.org/taglibs/response-1.0" prefix="response"%>
<response:addHeader name="Cache-Control">
    s-maxage=60
</response:addHeader>

Template developers need to be aware that using ESI imposes constraints on how they structure their templates. They must also be sure to set the s-maxage HTTP header in entry point JSPs (the ones that directly respond to HTTP requests rather than being included by other JSPs).