From 704ef9a95416dd1774aaac23bca9a7dc4aff9514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?UI=20=E8=AE=BE=E8=AE=A1?= Date: Thu, 21 May 2026 16:40:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(nginx):=20=E5=8E=BB=E6=8E=89=20immutable=20?= =?UTF-8?q?+=20=E7=BC=A9=E7=9F=AD=E7=BC=93=E5=AD=98=20=C2=B7=20=E8=BF=AD?= =?UTF-8?q?=E4=BB=A3=E6=9C=9F=20CSS/JS=20=E6=94=B9=E4=BA=86=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E8=83=BD=E7=AB=8B=E5=88=BB=E7=9C=8B=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 电商AI平台/nginx.conf | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/电商AI平台/nginx.conf b/电商AI平台/nginx.conf index 106342f..c2fd5f0 100644 --- a/电商AI平台/nginx.conf +++ b/电商AI平台/nginx.conf @@ -14,10 +14,23 @@ server { add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always; - # Cache static assets (CSS/JS/images/fonts) - location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp4|webm)$ { - expires 30d; - add_header Cache-Control "public, immutable"; + # 设计稿迭代期:CSS/JS 不带 hash,不能用 immutable,否则改了浏览器仍吃旧版 + # 缓存 1 小时 + must-revalidate(过期后用 If-Modified-Since 回源验证,服务器没改返回 304,改了取新文件) + location ~* \.(css|js)$ { + 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.