Edge Side Includes without Varnish

      Comments Off on Edge Side Includes without Varnish

Development on websites when the product will run on a Varnish'ed' production environment can be a pain in the ass. The xml tag that can be used to define Edge Side Includes can't be parsed by a standard browser. While developing you often look at a half rendered website implementation.

This is something you really don't want!

A solution to the problem is the use of Zend Framework's plugin controller architecture.

You can mimic the behavior of Varnish by just searching your body content and replacing the ESIs with the real content.

Zend Framework gives you the opportunity to hook into the dispatch loop that generates the body content of a request. While hooking into the shutdown method of the plugin controller you can search for ESIs using regular expressions.

The ESIs than can be replaced using streams with the added benefit of reading the HTTP headers to look for the same caching headers as Varnish would do. The replacement can than be cached using Zend_Cache, effectively copying all of the functionality and behavior of Varnish Edge Side Includes.

A more detailed explanation and source code can be found at my company's blog.