Skip to content

Instantly share code, notes, and snippets.

@section-io-gists
Last active September 19, 2017 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save section-io-gists/ff73003b6478aed4b82f95bd3eb4228a to your computer and use it in GitHub Desktop.
Save section-io-gists/ff73003b6478aed4b82f95bd3eb4228a to your computer and use it in GitHub Desktop.
Cache Static Content and also fix the Vary response header (Commonly needed when origin is responding with: Vary: Accept-Encoding,User-Agent)
#Varnish 4 config below
sub vcl_recv {
#Add font files to be cached as static caching checkbox misses .woff
if (req.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf|woff)(?=\?|&|$)") {
return (hash);
}
}
sub vcl_backend_response {
#Add font files to be cached as static caching checkbox misses .woff
if (beresp.status < 400) {
if (bereq.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf|woff)(?=\?|&|$)") {
set beresp.http.Vary = "Accept-Encoding";
set beresp.ttl = 1d;
unset beresp.http.set-cookie;
return (deliver);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment