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.