Plack::Middleware::ESI - PSGI middleware for Edge Side Includes (ESI)


version 0.1


  use Plack::Builder;

  my $app = sub {
      return [
        [ 'Content-Type' => 'text/plain' ],
          "The Google front page as plaintext: ",
          '<esi:include src="" />',
          "And a local request might be nice: ",
          '<esi:include src="/userinfo/" />',

  builder {
      enable "ESI";


This module provides rudimentary support for using Edge Side Includes in PSGI applications.

The primary aim is to support the same subset of features as the Varnish caching proxy server. Essentially, this means support for three ESI tags:

  • <esi:include src="..." /> - Include the contents of a remote or a local URL. Please note that the alt and onerror attributes are not supported.

  • <esi:remove>...</esi:remove> - Remove a section of the document.

  • <!--esi ...--> - Unhide whataver is inside the HTML/XML comment (which is normally the result of applying an ESI include tag).

The module only filters responses with a Content-Type of text/*, application/xml, or application/xhtml+xml. This obviously means that the Content-Type output header must have been set further down in the middleware stack (or, of course, in the original PSGI app itself), before the ESI middleware is applied.


Baldur Kristinsson <>