fix(nginx): 去掉 immutable + 缩短缓存 · 迭代期 CSS/JS 改了团队能立刻看到
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 9s

This commit is contained in:
UI 设计 2026-05-21 16:40:11 +08:00
parent e7c0a14f75
commit 704ef9a954

View File

@ -14,10 +14,23 @@ server {
add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
# Cache static assets (CSS/JS/images/fonts) # 设计稿迭代期:CSS/JS 不带 hash,不能用 immutable,否则改了浏览器仍吃旧版
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp4|webm)$ { # 缓存 1 小时 + must-revalidate(过期后用 If-Modified-Since 回源验证,服务器没改返回 304,改了取新文件)
expires 30d; location ~* \.(css|js)$ {
add_header Cache-Control "public, immutable"; expires 1h;
add_header Cache-Control "public, must-revalidate";
}
# 图片/字体/媒体:可以缓存稍长(改动频率低),仍允许重新验证
location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp4|webm)$ {
expires 7d;
add_header Cache-Control "public, must-revalidate";
}
# HTML:不进浏览器磁盘缓存,每次都问服务器有没有新版本
location ~* \.html$ {
add_header Cache-Control "no-cache, must-revalidate" always;
expires off;
} }
# Multi-page (not SPA): try exact file, then .html fallback (friendly URLs), then 404. # Multi-page (not SPA): try exact file, then .html fallback (friendly URLs), then 404.