Conditionally Disabling GZIP in Order to Serve ESI


#1

Fastly’s version of Varnish currently doesn’t support the use of ESI with GZIP. But you can conditionally disable GZIP in order to serve ESI when it’s appropriate for your service.

Assuming you’ve already had custom vcl enabled, you’ll then want to insert some ESI logic into the Fastly boilerplate under vcl_fetch.

In this example, we’ll enable ESI based on Content-Type:

sub vcl_fetch {
#FASTLY fetch
  if ( beresp.http.Content-Type ~ "^text/html" ) {
    esi;
  }

Next, you’ll want to add unset bereq.http.accept-encoding to vcl_miss:

sub vcl_miss {
unset bereq.http.accept-encoding;
#FASTLY miss
  return(fetch);
}

Finally, you’ll create a GZIP object in the UI and—based on our example above—remove text/html from the content types to be compressed and the html extension, if it’s there.

These steps should ensure that when you’re not serving ESI, you’re still compressing, but when you are serving ESI, your content remains uncompressed, allowing your ESI content to render consistently.


#2

There’s a missing semicolon after unset bereq.http.accept-encoding


#3

Thanks @Frank_Farmer


#4

Hi Justin,

I ping with this question every now and then.
Is there any plan to fix ESI with GZip limitation? After all Varnish 3 does support it.

Now question related to workaround mentioned here. Turning gzip off for all HTML would drastically increase content size. Wouldn’t it seriously impact on performance of site that uses this workaround?


#5

You’re in luck! We’re almost ready to announce support but not quite yet…
If you’d like to test it out in the meantime send in a Support ticket and we can let you the current state.


#6

Wow! That’s great to hear.
Is there any insight on when the support will be announced?


#7

Don’t jinx it! :sweat_smile:
Seriously though, the release date hasn’t been given, but it’s being tested by customers now, so it won’t be too long…