We're trying to configure our sites running D7 to use ESIs with Varnish 2.1.5, and having a hard time figuring this out.

We have a file /test.php that is being included in the template via esi so it appears on all pages of our site. The call to the file is through (in the template)

<esi:include src="/test.php" />

Relevant vcl conf is:

sub vcl_fetch {
  // enable esi
  // if url is test.php, set ttl to 15 s
  if (req.url == "/test.php") {
    unset beresp.http.set-cookie;
    set beresp.ttl = 15s;

The text from test.php appears when users are logged in, but does not appear when they are logged out -- which is what we're after. This is without the ESI module as that is for authenticated users.

  • 1
    "This is without the ESI module as that is for authenticated users." The ESI module works with anonymous and authenticated users; just be aware that all anonymous users are treated the same. – mikeytown2 Jul 26 '12 at 20:48
  • @mikeytown2 My understanding is that with the ESI module one can cache pages when users are authenticated, and also display fragments of dynamic content. Is my understanding amiss? – KM. Jul 26 '12 at 21:02
  • 1
    ESI in its current form is there to display fragments of dynamic content. It really doesn't care if your logged in or not as it treats user 0 (anonymous) as one user. So if all anonymous users are going to get the same experience you shouldn't have any issues with ESI. – mikeytown2 Jul 26 '12 at 21:05
  • 1
    @mikeytown2: Thanks for the clarification, the 1st line on project page: "ESI - or Edge Side Includes - is a high performance caching solution for Authenticated users" thew me off. – KM. Jul 27 '12 at 13:22

Try turning off Anonymous caching and see what results you get (caching should be handled by Varnish).

  1. Go to admin/config/development/performance
  2. Uncheck Cache pages for anonymous users
|improve this answer|||||
  • Does anonymous caching on that page imply caching at the Drupal level? – KM. Jul 26 '12 at 20:55
  • Yes, it caches at the Drupal level – Johnathan Elmore Jul 26 '12 at 21:03
  • Thanks this works! To better my understanding: A combination of "flush all caches" and varnish restart should clear all anonymous caches, right? I tried this, but the esi content was only visible when users were logged in. Why would that be? – KM. Jul 27 '12 at 13:20
  • I'm not real savvy on ESI, but I would check if Varnish is actually processing pages that are cached by Drupal, or if it's Apache that's processing it. In other words, maybe Apache is handling the request instead of Varnish, and Apache cannot handle the <esi>. Lots of assumptions in this comment! Just throwing out some ideas. – Johnathan Elmore Jul 27 '12 at 17:30
  • For clearing the Varnish cache you should consider using drupal.org/project/purge and drupal.org/project/flush_page_cache which helps you flush the drupal cache/ varnish cache for a particular page when used along with purge. – Gokul N K Aug 21 '13 at 5:46

I have a working instance with Drupal7, Varnish and ESI in working state[Th ESI tags are getting replaced for both Anonymous and logged in users].

I can confirm that ESI tags work well with Drupal Page Cache. I don't see a reason you need to disable the Drupal Page cache for ESI tags to work.

And regarding the behavior that you were experiencing, I think the anonymous page cache was built you added your ESI tag and hence it was not displaying. I think clearing Drupal Cache and Varnish Cache could have just fixed your issue.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.