View_428928_58900288

Edge Side Includes (ESI) and Rails in Development Mode

How ESIs Work

As part of my work with LVS

Using Varnish in Production

What to do in Development

Russ Smith’s had the same thoughts as I did, it’s not ideal to be having to run Varnish in development mode:

I decided to look into what it would take to get Rails, Varnish and ESI working. My biggest complaint about this process is that it works great in production but it makes local development a royal pain. You either just have to imagine the included content is there or you have to setup a local varnish server and work through the proxy. Neither sound fun.

His solution involves using a helper to insert the ESI tags:

When your in development mode, your page will make an AJAX call to load the content. It will look exactly the same as if it was loaded through ESI and it will go through the Rails stack so you won’t get any different behaviour in production mode. If your in production mode, it will just output the ESI include tag.

My problem with this solution is that there may be other environments where you don’t want to run Varnish, but not use a fundamentally different mechanism to pull in the content. As an example (although my code doesn’t take this in to account either) you may want to pull the ESIs from a different domain name (AJAX won’t allow this) from the one the main page is hosted on. This is fine according to the W3C spec.

Middleware solution

Code example:

    do.something(:name => ‘foo’)

Other articles you may like:

0 Comments so far

Click here to have your say...


You can use <b>+</b>, <i>+</i> and <blockquote>+</blockquote>