Skip to content

Commit 98a8ea3

Browse files
authored
Merge pull request #117 from fastly/vcl_fixes
Adding few VCL optimizations
2 parents bca6863 + f4f3ddc commit 98a8ea3

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

Diff for: etc/vcl_snippets/fetch.vcl

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Remove Set-Cookies from responses for static content
1818
# to match the cookie removal in recv.
19-
if (req.url ~ "^/(pub/)?(media|static)/") {
19+
if (req.http.x-long-cache || req.url ~ "^/(pub/)?(media|static)/") {
2020
unset beresp.http.set-cookie;
2121

2222
# Set a short TTL for 404's since those can be temporary during the site build/index
@@ -46,8 +46,8 @@
4646
# compress it
4747
set beresp.http.x-compress-hint = "on";
4848
} else {
49-
# enable gzip for all static content
50-
if (http_status_matches(beresp.status, "200,404") && (beresp.http.content-type ~ "^(application\/x\-javascript|text\/css|application\/javascript|text\/javascript|application\/json|application\/vnd\.ms\-fontobject|application\/x\-font\-opentype|application\/x\-font\-truetype|application\/x\-font\-ttf|application\/xml|font\/eot|font\/opentype|font\/otf|image\/svg\+xml|image\/vnd\.microsoft\.icon|text\/plain)\s*($|;)" || req.url.ext ~ "(?i)(css|js|html|eot|ico|otf|ttf|json)" ) ) {
49+
# enable gzip for all static content except
50+
if ( !req.http.x-long-cache && http_status_matches(beresp.status, "200,404") && (beresp.http.content-type ~ "^(application\/x\-javascript|text\/css|application\/javascript|text\/javascript|application\/json|application\/vnd\.ms\-fontobject|application\/x\-font\-opentype|application\/x\-font\-truetype|application\/x\-font\-ttf|application\/xml|font\/eot|font\/opentype|font\/otf|image\/svg\+xml|image\/vnd\.microsoft\.icon|text\/plain)\s*($|;)" || req.url.ext ~ "(?i)(css|js|html|eot|ico|otf|ttf|json)" ) ) {
5151
# always set vary to make sure uncompressed versions dont always win
5252
if (!beresp.http.Vary ~ "Accept-Encoding") {
5353
if (beresp.http.Vary) {

Diff for: etc/vcl_snippets/miss.vcl

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# Deactivate gzip on origin
2-
unset bereq.http.Accept-Encoding;
1+
# Deactivate gzip on origin. This is so we can make sure that ESI fragments
2+
# come uncompressed. X-Long-Cache objects can be left untouched.
3+
if ( !req.http.x-long-cache ) {
4+
unset bereq.http.Accept-Encoding;
5+
}

Diff for: etc/vcl_snippets/pass.vcl

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
# Deactivate gzip on origin
2-
unset bereq.http.Accept-Encoding;
1+
# Deactivate gzip on origin. This is so we can make sure that ESI fragments
2+
# come uncompressed. X-Long-Cache objects can be left untouched.
3+
if ( !req.http.x-long-cache ) {
4+
unset bereq.http.Accept-Encoding;
5+
}
36

47
# Increase first byte timeouts for /admin* URLs to 3 minutes
58
if ( req.url ~ "^/(index\.php/)?admin(_.*)?/" ) {

Diff for: etc/vcl_snippets/recv.vcl

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
# Pass on checkout URLs. Because it's a snippet we want to execute this after backend selection so we handle it
8383
# in the request condition
84-
if (req.url ~ "/(catalogsearch|checkout|customer/section/load)") {
84+
if (!req.http.x-long-cache && req.url ~ "/(catalogsearch|checkout|customer/section/load)") {
8585
set req.http.x-pass = "1";
8686
# Pass all admin actions
8787
} else if ( req.url ~ "^/(index\.php/)?admin(_.*)?/" ) {
@@ -94,7 +94,7 @@
9494

9595

9696
# static files are always cacheable. remove SSL flag and cookie
97-
if (req.url ~ "^/(pub/)?(media|static)/.*") {
97+
if (req.http.x-long-cache || req.url ~ "^/(pub/)?(media|static)/.*") {
9898
unset req.http.Https;
9999
unset req.http.Cookie;
100100
}

0 commit comments

Comments
 (0)