perf(static): 带 hash 的前端资源缓存一年,index.html 不缓存
线上实测 /assets/index-u1PUen4p.js 返回的是 express.static 的默认 Cache-Control: public, max-age=0 —— 每开一次页面就要为每个 JS/CSS 跑一趟 回源校验。而这些文件名里本来就带内容 hash,内容一变文件名就变。 分两档: assets/* max-age=31536000, immutable(连 304 都不用问) index.html no-cache index.html 必须不缓存:它文件名固定、里面引用的才是带 hash 的资源名。 缓存住的话发了新版用户还拿着旧 index.html、指向旧资源,等于白更新。 SPA fallback 那条单独加了一遍 no-cache —— 它走 sendFile,不经过 express.static 的 setHeaders,/orders 这类深链拿到的同样是 index.html。 Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
3380dbc9d7
commit
dc607e4ea3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "trade-management-frontend",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "外贸供应链管理系统 - 前端",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user