Thursday, March 17, 2016

HTTP Caching with ESI


In general, the idea behind caching is to improve web performance by delivering content more quickly and to reduce the load on the origin servers.

Caching static content, such as images, JavaScript and CSS files, and web content that rarely changes is a relatively straightforward process. Cache updates can be handled by regular timeouts or conditional gets etc.

Caching personalised content is generally not possible, because the server’s response to each request for the same resource is different. Techniques such as server side includes (SSI) and edge side includes (ESI) can help to assemble the page.

Lets take a deeper look at ESI and see how it works -
By definition, ESI is a markup language for edge level dynamic web content assembly. The purpose of ESI is to tackle the problem of web infrastructure scaling.

ESI is implemented by different content delivery networks such as Akamai, and by some caching proxy servers such as Varnish. Akamai also adds additional features to the version they support.

So how ESI is implemented?
ESI element tags are inserted into HTML or other text based content during creation. Instead of being displayed to viewers, these ESI tags are directives that instruct an ESI processor to take some action. The XML based ESI tags indicate to the edge-side processing agent the action that needs to be taken to complete the page's assembly.

One simple example of an ESI element is the include tag which is used to include content external to the page. An ESI include tag placed in-line within an HTML document would look like this:


<esi:include src="http://yoursite.com/page1.html" alt="http://beta.yoursite.com/page2.html" onerror="continue">  </esi:include>


In this case the ESI processor would retrieve the src URL, or failing that the alt URL. The ESI system is usually a caching proxy server so it may have a local copy of these files which it can insert without going back to the server. Alternatively, the whole page with the ESI tags may be cached, and only the ESI requests may be made to the origin server. This allows different caching times for different parts of the page, or different degrees of personalisation.



There are four main features in ESI - 
  • Inclusion of page fragments
  • Variables which can be set from cookies or HTTP headers and then used in other ESI statements or written into markup
  • Conditions so that different markup can be used based on variables, for example if a cookie is set or not
  • Error handling for failover if an origin server is unavailable.


Which CDNs support ESI?
ESI is currently supported by CDNs like Akamai, Fastly, CloudFlare and caching proxy servers like Varnish and Squid. Although many do not implement the complete specification, Akamai also adds additional features to the version they support.


Reference and next steps - 


















Popular Posts