Skip to content

Commit 7b6fcec

Browse files
committed
MAGETWO-33342: Static files must not be cached by Varnish by default
1 parent ef27f94 commit 7b6fcec

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ sub vcl_recv {
9696
set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
9797
set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
9898

99-
# static files must not be cached by default
99+
# Static files caching
100100
if (req.url ~ "^/(pub/)?(media|static)/.*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|html|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|tiff|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)$") {
101+
# Static files should not be cached by default
101102
return (pass);
103+
104+
# But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
105+
#unset req.http.Https;
106+
#unset req.http./* {{ ssl_offloaded_header }} */;
107+
#unset req.http.Cookie;
102108
}
103109

104110
return (hash);

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ sub vcl_recv {
9797
set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
9898
set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
9999

100-
# static files must not be cached by default
100+
# Static files caching
101101
if (req.url ~ "^/(pub/)?(media|static)/.*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|html|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|tiff|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)$") {
102+
# Static files should not be cached by default
102103
return (pass);
104+
105+
# But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
106+
#unset req.http.Https;
107+
#unset req.http./* {{ ssl_offloaded_header }} */;
108+
#unset req.http.Cookie;
103109
}
104110

105111
return (hash);

0 commit comments

Comments
 (0)