Gzipping uncached content
I’m using vcl to gzip my site’s content using a very similar bit of VCL in vcl_fetch
to that generated by fastly’s UI:
if ( beresp.http.Content-Type ~ "^(text/html|application/x-javascript|text/css|application/javascript|text/javascript|application/json|application/rss)" ) {
if ( req.http.Accept-Encoding ~ "gzip") {
# Header rewrite Force GZIP : 10
set beresp.gzip = true;
}
# Header rewrite Vary Encoding : 10
if (beresp.http.Vary) {
set beresp.http.Vary = beresp.http.Vary ", Accept-Encoding";
} else {
set beresp.http.Vary = "Accept-Encoding";
}
}
Towards the end of vcl_fetch
I have the following, to avoid caching personalised pages:
if (beresp.http.Cache-Control ~ "private") {
set req.http.Fastly-Cachetype = "PRIVATE";
return (pass);
}
return(deliver);
gzip is working for all pages except for the personalised, uncached ones, so it looks like gzipping is only applied to cached content.
Is my diagnosis correct, and is there any way I can get fastly to gzip uncached content?
-
It's a shame Fastly can't just handle the GZIP in these scenarios, provided the
Cache-Control
header doesn't containno-transform
, because I'm sure their stack will be much more optimised for this than most client's origin servers.That said, we've managed to work around this.
I'm not sure what your back-end technology is, but we implemented GZIP at the origin for any non-idempotent request methods (e.g. POST/PUT/PATCH/DELETE) and any idempotent requests which respond with a
Cache-Control
header containingprivate
(neither are cached by Fastly, by default). This might put a little additional load on your origin, but does solve the problem – we saw a huge reduction in bandwidth utilisation from this.
Please sign in to leave a comment.
Comments
3 comments