Varnish Caching ESI Fragment

Dami Onajole dami.onajole at
Mon Aug 15 15:37:12 CEST 2011

Hi All,

I am having problem using ESI with Varnish 3.0 successfully. I have an ESI
fragment that displays a notice for logged in users, included via an ESI
tag. However, varnish caches the included ESI fragment, so changes made to
the fragment, either manually, or as a result of a session does not reflect
in the including (and cached) web page.

ESI tag as used:

<esi:inlcude src="path/to/fragment.esi">

VCL configuration:

sub vcl_recv {
  if (req.url ~ "[A-Za-z0-9_-]*.esi$") {
    return (pass);

  if (req.http.cookie) {
    set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?",
     if (req.http.cookie ~ "^ *$") {
         remove req.http.cookie;

  remove req.http.cookie;
  remove req.http.etag;

sub vcl_fetch {
  remove beresp.http.Set-Cookie;
    remove beresp.http.ETag;
 #do esi processing
set beresp.do_esi = true;
 if (bereq.url ~ "[A-Za-z0-9_-]*.esi$") {
   set beresp.ttl = 0s;
 } else {
   set beresp.ttl = 24h;

My assumptions are:

1) Varnish will make requests to "path/to/fragment.esi" and the re-assemble
cache web page every time it fetches from its cache store, especially since
beresp.ttl is set to 0s for every .esi fragments
2) Varnish does not store the ESI fragments together with a web page in its
cache store


*Damilare Onajole*
Python Developer

*Large Blue*
120 Long Acre, Covent Garden, London. WC2E 9PA.

+44 (0)20 7240 0330


Large Blue is a committed Carbon Neutral company.
Please consider the environment before printing this email
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list