Gzipping uncached content


#1

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?


#2

You’re correct: we only gzip content that we can cache. Or in other words we don’t gzip content that is not stored by us.

No, there’s no way to force gzip for those requests. The responses just come straight from the origin server and we don’t alter them.


#3

@justin

No, there’s no way to force gzip for those requests. The responses just come straight from the origin server and we don’t alter them.

we do have a need to gzip such “uncached content” how can we go about it?


#4

It’s a shame Fastly can’t just handle the GZIP in these scenarios, provided the Cache-Control header doesn’t contain no-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 containing private (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.