From 0db60d8b3f41899e60dfb903876e4f7267b92940 Mon Sep 17 00:00:00 2001 From: EmeraldCoder Date: Thu, 26 Aug 2021 20:57:06 -0400 Subject: [PATCH] Improve caching strategy for static assets with content hash --- Dockerfile | 3 ++- nginx/default.conf | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 nginx/default.conf diff --git a/Dockerfile b/Dockerfile index 3444a32..ab5c10a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,3 @@ FROM nginx:alpine -ADD ./dist /usr/share/nginx/html \ No newline at end of file +ADD ./dist /usr/share/nginx/html +ADD ./nginx /etc/nginx/conf.d \ No newline at end of file diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..8eb031f --- /dev/null +++ b/nginx/default.conf @@ -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"; + } + } +} \ No newline at end of file