Conditionally Disabling GZIP in Order to Serve ESI
[Edit: ESI + GZIP can now be supported in certain circumstances. Please contact support@fastly.com to discuss turning this on. Note: You will require a paid account and a TLS product with us in order to do this].
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.
-
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?
-
Hi @markwainwright. Enabling will require emailing support@fastly.com. It's fairly quick and easy to do now.
-
Hi Chaim Klar
If you're not seeing ESI executing where you believe it should, it's likely to be because the content is coming in as compressed.
I'm glad you found a solution but if you need anything else, do send it in as a ticket via the Support portal or an email to support@fastly.com so we can investigate.
Please sign in to leave a comment.
Comments
9 comments