For essentially static content or other cacheable content, edge-side
includes are an attractive way to provide personalized o-wrap (e.g.
"Hello, %{your_name}") on high-volume sites. This is a proposal for a
middleware which makes it easy.

The setup is a WSGI-application which returns cacheable HTML
responses. An HTML region which varies ("vary") on some set of
variables will be marked up as follows:

  <span esi:vary="remote_user" esi:id="pretty_username">John</span>

The middleware will replace this segment with an edge-side include
(here ``$url`` is the request url):

  <esi:include src="$url?esi=pretty_username" />

The middleware will then mem-cache the HTML fragment for this particular user.

When an ESI-request (from the proxy-server) carries a header which
matches this "vary" value, the fragment is returned. If not, the
request is let through. It then mem-caches this and other ESI
fragments in the response, but returns only the requested fragment.

The middleware can even come equipped with a memcache-enabled ESI
implementation; it should not be difficult to implement this subset of
the ESI namespace (just the ``esi:include`` controller). This would be
useful in a development environment.


Simple, flexible, transparent, "true middleware".


The subrequest (which is for a full HTML document) is likely more
expensive than returning just the HTML fragment using a dedicated

Obviously, the middleware should only act on GET.

Comments appreciated.

Repoze-dev mailing list

Reply via email to