Last active
September 19, 2017 22:13
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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