fix(nginx): 强制 index.html/sw.js no-cache + 静态资源 immutable,根治部署后旧页面缓存

- location = /index.html、/sw.js、/manifest.webmanifest 加 no-cache,must-revalidate(PWA 预缓存不再赖旧版 my-ip 等页面)
- /assets/ 内容哈希资源 immutable 长缓存
- location / 兜底 no-cache;已部署验证线上响应头;CHANGELOG 补条
This commit is contained in:
personal827 committed 2026-11-01 02:20:13 +08:00
1 parent f73d7247bb
commit e48d165741
2 files changed
+26

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. See [standa
### ✨ 新功能
- **文档翻译支持扫描件/图片自动 OCR**:非纯文字文档(扫描版 PDF、截图、照片、带文字图片)先自动 OCR 识别文字再整篇翻译,扫描版 PDF 逐页渲染识别(单文档最多 30 页),图片可直接上传翻译;结果标注「已OCR识别 N 页」,页面附处理说明
- **修复「改版后用户看到旧页面」缓存问题**:nginx 对 `index.html`/`sw.js`/`manifest` 强制 `Cache-Control: no-cache, must-revalidate`(每次重新校验,杜绝 PWA 预缓存赖旧),对内容哈希静态资源 `immutable` 长缓存(加载更快),部署后无需用户强刷即见新版
- **新增「本机IP查询」**(`/my-ip`,Network 分组,免费不授权):仅显示**用户端**公网 IPv4/IPv6 地址与所属地(多源容错、中文归属地、一键复制),不显示服务器地址;IPv6 不支持时明示「不支持 IPv6」并给出五步开启教程
- **本站 IPv6 直连(速度更快)**:新增 `itv6.88531.cn`(AAAA→本机移动原生 v6,4443 防封端口 + 443,宝塔 nginx 双栈 + acme 证书 + DDNS 覆盖);页面顶部横幅「本站已支持 IPv6 访问,速度更快」,支持 IPv6 的用户一键切换直连
- **连接热门地点延迟**:进入页面自动测量到 9 个热门地点(本站/清华 TUNA/阿里云/腾讯云/华为云/中科大/香港 Fedora/日本 JAIST/Cloudflare)的网络延迟,支持一键重新测速
+25
View File
@@ -64,7 +64,32 @@ server {
proxy_read_timeout 30s;
}
# ---- SPA shell & service worker: MUST revalidate every load ----
# Without this header browsers heuristically cache index.html/sw.js and the
# PWA keeps serving a stale precache after deploys (2026-10-30: users were
# stuck on an old my-ip page that leaked the server egress IP).
location = /index.html {
add_header Cache-Control "no-cache, must-revalidate";
try_files $uri =404;
}
location = /sw.js {
add_header Cache-Control "no-cache, must-revalidate";
add_header Service-Worker-Allowed "/";
try_files $uri =404;
}
location = /manifest.webmanifest {
add_header Cache-Control "no-cache, must-revalidate";
try_files $uri =404;
}
# hashed build assets are content-addressed: cache forever
location /assets/ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
location / {
add_header Cache-Control "no-cache, must-revalidate";
try_files $uri $uri/ /index.html;
}
}