From 9d3938b94f0ad02560a8cd74833fa9dc0484ba45 Mon Sep 17 00:00:00 2001 From: hwj Date: Fri, 17 Jul 2026 17:48:33 +0800 Subject: [PATCH] =?UTF-8?q?build=EF=BC=9Ang=E9=85=8D=E7=BD=AE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=89=8D=E7=AB=AF=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nginx.conf b/nginx.conf index 5729e577..8c3beeed 100644 --- a/nginx.conf +++ b/nginx.conf @@ -92,6 +92,21 @@ server { proxy_set_header X-Real-IP $remote_addr; } + # Vite 将这些第三方库输出为带内容哈希的独立文件。文件内容变化时 URL 会变化, + # 因此可以长期缓存;业务代码不会匹配此规则。 + location ~ ^/assets/(?:element-plus|hiprint|form-create|wangeditor|echarts|cropperjs|vue)-[A-Za-z0-9_-]+\.js$ { + root /usr/share/nginx/html; + try_files $uri =404; + add_header Cache-Control "public, max-age=31536000, immutable" always; + } + + # 项目业务 JS 不使用浏览器缓存,确保每次访问均会检查线上最新版本。 + location ~ ^/assets/.*\.js$ { + root /usr/share/nginx/html; + try_files $uri =404; + add_header Cache-Control "no-store, max-age=0" always; + } + location / { root /usr/share/nginx/html; index index.html index.htm;