Skip to content

Instantly share code, notes, and snippets.

@codl
Last active October 7, 2021 00:55
Show Gist options
  • Save codl/b17c81bd0f2e7471243552e00bbdbd44 to your computer and use it in GitHub Desktop.
Save codl/b17c81bd0f2e7471243552e00bbdbd44 to your computer and use it in GitHub Desktop.
sub vcl_recv {
if(req.http.Accept-Encoding ~ "br") {
set req.http.X-brotli = "true";
}
}
sub vcl_hash {
if(req.http.X-brotli == "true") {
hash_data("br");
}
}
sub vcl_hit {
if(req.http.X-brotli == "true") {
if(obj.ttl <= 0 && obj.grace > 0){
set req.http.X-brotli-bgfetch = "true";
}
}
}
sub vcl_backend_fetch {
if(req.http.X-brotli == "true") {
if(req.http.X-brotli-bgfetch == "true") {
set bereq.http.accept-encoding = "br";
# we don't want a 304, so clear out last modified and etag
unset bereq.http.if-modified-since;
unset bereq.http.if-none-match;
}
}
unset bereq.http.X-brotli;
unset bereq.http.X-brotli-bgfetch;
}
sub vcl_backend_response {
# blah blah
# set your default ttls here
beresp.ttl = 1y;
if(req.http.X-brotli == "true") {
if(req.http.X-brotli-bgfetch != "true") {
beresp.ttl = 0;
beresp.grace = 1h;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment