Skip to content

Commit

Permalink
Improve caching strategy for static assets with content hash
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldCoder committed Aug 27, 2021
1 parent e63453b commit 0db60d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FROM nginx:alpine
ADD ./dist /usr/share/nginx/html
ADD ./dist /usr/share/nginx/html
ADD ./nginx /etc/nginx/conf.d
19 changes: 19 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html;

# Default caching strategy based on the etag feature (for stuff like index.html and site.webmanifest that don't have a content hash in the name)
etag on;
add_header Cache-Control "no-cache";

# Caching strategy for static assets (Vue build those assets with a content hash in the name, so etag is not usefull and the cache will busted automatically if the content of the file change)
location ~ ((\/css)|(\/js)|(\/img)) {
etag off;
add_header Cache-Control "public,max-age=31536000,immutable";
}
}
}

0 comments on commit 0db60d8

Please sign in to comment.