From 013f3bc50551fb899fd4f223395dceef6ca0344a Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Fri, 19 Jun 2026 18:51:40 +0800 Subject: [PATCH] fix(docker): prevent stale service worker caching (#5973) --- docker/nginx.common.conf | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docker/nginx.common.conf b/docker/nginx.common.conf index 528bd4c1..21d70611 100644 --- a/docker/nginx.common.conf +++ b/docker/nginx.common.conf @@ -76,6 +76,20 @@ location ~* \.(png|jpg|jpeg|gif|ico|svg)$ { add_header Cache-Control "public, immutable"; } +# Service Worker 和 Web App Manifest 需要稳定 URL 但不能长缓存,否则前端更新时浏览器可能继续注册旧版本。 +location = /service-worker.js { + expires off; + add_header Cache-Control "no-cache, must-revalidate"; + try_files $uri =404; +} + +location = /manifest.webmanifest { + expires off; + default_type application/manifest+json; + add_header Cache-Control "no-cache, must-revalidate"; + try_files $uri =404; +} + # JS 和 CSS 静态资源缓存(排除 /api/v1 路径) location ~* ^/(?!api/v1).*\.(js|css)$ { try_files $uri =404; @@ -86,8 +100,7 @@ location ~* ^/(?!api/v1).*\.(js|css)$ { # assets目录 location /assets { - expires 1y; - add_header Cache-Control "public, immutable"; + add_header Cache-Control "public, max-age=31536000, immutable"; } # 站点图标