Nginx – Gzip vs. Reverse Proxy Cache

cachegzipnginxruby-on-railsvarnish

I have a mostly static site running on Ruby on Rails that is using the Varnish reverse proxy cache to save on hits to the Rails backend.

The problem is that a user can login to the site and when they do we use ESI (edge side includes) to show user specific parts of the page.

Using ESI means that we have to disable Gzip compression on the Rails backend (using Nginx+passenger) or varnish cannot parse the data returned from the backend in order to run ESI processing.

My question is, do the benefits of using a reverse proxy cache outweigh the benefits of gzipping all your content? Or should I try to get rid of ESI complete and have the best of both worlds?

Best Answer

You could get the best of both worlds if you arrange things like so:

User -> nginx -> Varnish -> Rails

Turn gzip compression on from nginx to user. That's the slowest segment and also the most costly. I am assuming that your nginx, Varnish and Rails instances are local to each other. Your local bandwidth should be more than sufficient. Besides it does not make too much sense to gzip only to decompress to assemble the ESI.