fix(docker): prevent stale service worker caching (#5973)

This commit is contained in:
InfinityPacer
2026-06-19 18:51:40 +08:00
committed by GitHub
parent de9fd75cac
commit 013f3bc505

View File

@@ -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";
}
# 站点图标