Archive for the ‘Varnish’ Category

Cross-domain XHR with Varnish

Cross-domain XHR (AJAX) requests can be an issue. There are workarounds like JSONP but sometimes JSONP is not available, or you need a POST request, or you have other special requirements that require usage of XHR. In that case a webproxy on your own domain is often used to resolve the crossdomain issue.

There are many examples how to solve this inside your application, but when you just need to relay a request you can do this easily with Varnish. That way you don’t need to build anything in your application and you get a high-performance ‘proxy’.

Read more…

Categories: Varnish Tags: , ,

Controlling Varnish ESI inside your application

July 5, 2010 2 comments

For me one of the best features of Varnish is ESI (Edge Side Includes).  It allows you to combine elements with different lifetimes into a single page. This way you don’t need to regenerate a complete page as soon as a news listing somewhere on the page changes. And you can still cache pages while displaying user-specific information somewhere on the page.
This lowers the load on your application even further and it can also help in simplifying your application, by focussing purely on the content of the page and loading all other elements via ESI.

There is a small drawback though, parsing for ESI comes at a cost. Although Varnish performs well even with ESI enabled, the effect is noticable. And binary files should be excluded from ESI parsing all together. The usual solution is to enable ESI only for specific requests in your VCL file. A typical example:

sub vcl_fetch {
    if (req.url == "/news") {
        esi;  /* Do ESI processing */

With this solution you might end up adding all URLs that need to be parsed into your VCL file, complicating application development. Or you can decide to parse all text/html content, so you don’t need to frequently alter your VCL. Both solutions work, but are not optimal. The main issue is that your application should decide when to apply ESI to the content, not Varnish. The knowledge to base this decision on is in your application domain. When developing a page in your application you know whether you want to use ESI, and you should be able to do so easily, right inside the application.

Read more…