From 6682810c00990c99d56b9da2b2359cb35baa6ad4 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 24 May 2026 22:04:44 -0400 Subject: [PATCH] Nginx: no-cache on index.html, long cache on hashed assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this the browser caches index.html, which contains references to the current build's JS bundle filename. After a redeploy the new bundle has a different hash, but the browser still loads the old index.html → requests the old bundle → may 404 or load stale code. Symptom: Ctrl+Shift+R required after every update to see the story. index.html: Cache-Control no-cache/no-store/must-revalidate JS/CSS/font/image assets: max-age=31536000, immutable (safe because Vite includes a content hash in every filename) Co-Authored-By: Claude Sonnet 4.6 --- frontend/nginx.conf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frontend/nginx.conf b/frontend/nginx.conf index ef1a289..b73af29 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -4,6 +4,20 @@ server { root /usr/share/nginx/html; index index.html; + # index.html must never be cached — it references hashed asset filenames + # that change on every build. Stale HTML → wrong JS bundle → broken app. + location = /index.html { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + } + + # Hashed JS/CSS/image assets are safe to cache forever — the filename + # changes whenever the content changes, so there's no stale-file risk. + location ~* \.(?:js|css|woff2?|svg|png|jpg|ico)$ { + add_header Cache-Control "public, max-age=31536000, immutable"; + try_files $uri =404; + } + location / { try_files $uri $uri/ /index.html; }