Skip to content

Enable browser caching of signed assets #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions etc/vcl_snippets/fetch.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

}

# Force caching for signed cached assets.
if (req.http.x-long-cache) {
set beresp.ttl = 31536000s;
set beresp.http.Cache-Control = "max-age=31536000";
}

if (beresp.http.Content-Type ~ "text/(html|xml)") {
# enable ESI feature for Magento response by default
esi;
Expand Down
3 changes: 3 additions & 0 deletions etc/vcl_snippets/recv.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
set req.url = re.group.2;
}

unset req.http.x-long-cache;

# Rewrite /static/versionxxxxx URLs. Avoids us having to rewrite on nginx layer
if (req.url ~ "^/static/version(\d*/)?(.*)$") {
set req.url = "/static/" + re.group.2 + "?" + re.group.1;
set req.http.x-long-cache = "1";
}

# User's Cookie may contain some Magento Vary items we should vary on
Expand Down