Skip to content

Instantly share code, notes, and snippets.

@section-io-gists
Last active December 15, 2017 05:03
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/2a9e40238fffec56d3be to your computer and use it in GitHub Desktop.
Save section-io-gists/2a9e40238fffec56d3be to your computer and use it in GitHub Desktop.
section.io VCL - Static Caching
#section.io VCL sample. Copy paste into your section.io account to implement instantly
#vcl_recv - copy this code into the section called sub vcl_recv
if (req.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf)(?=\?|&|$)") {
unset req.http.Cookie;
#Varnish <= 3.x calls this "return (lookup);" instead of "return (hash);"
return (hash);
}
#vcl_backend_response - copy this code into the section called sub vcl_backend_response
#Varnish <= 3.x calls this "vcl_fetch" instead of "vcl_backend_response"
if ((bereq.url ~ "\.(css)(?=\?|&|$)" && beresp.http.Content-Type ~ "text/css")
|| (bereq.url ~ "\.(jpe?g|png|gif|ico)(?=\?|&|$)" && beresp.http.Content-Type ~ "image/")
|| (bereq.url ~ "\.(js)(?=\?|&|$)" && beresp.http.Content-Type ~ "javascript")
|| (bereq.url ~ "\.(swf)(?=\?|&|$)" && beresp.http.Content-Type ~ "application/x-shockwave-flash")
|| (bereq.url ~ "\.(woff)(?=\?|&|$)" && beresp.http.Content-Type ~ "font")) {
set beresp.ttl = 28800s; #The number of seconds to cache inside Varnish
set beresp.http.Cache-Control = "max-age=28800"; #The number of seconds to cache in browser
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment