Skip to content

fix(gateway): restore immutable caching for 12-char hashed assets - #55

Open
yorkane wants to merge 1 commit into
RyensX:mainfrom
yorkane:codex/asset-cache-fix
Open

yorkane wants to merge 1 commit into
RyensX:mainfrom
yorkane:codex/asset-cache-fix

Conversation

@yorkane

@yorkane yorkane commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

问题

官方 renderer 的所有静态资源响应都带 cache-control: no-store,导致每次刷新整包 JS/CSS/字体/图片全部重新下载,移动端弱网下首屏极慢。按设计只有入口 HTML 和动态注入脚本该 no-store,content-hash 资源应 immutable 长缓存。

根因

gateway/runtime/http/static-assets.cjs 里判定 content-hash 资源的正则是
-[A-Za-z0-9_-]{8}\.(?:avif|css|gif|ico|jpe?g|js|png|svg|webp|woff2?)$,即 hash 必须是恰好 8 位且以连字符分隔。而官方 bundle 已由 Vite 切到 rolldown,hash 变成 12 位,且部分 wasm 用点分隔(如 DocumentFormat.OpenXml.4g1x2psnat.wasm)。结果 8000+ 个 chunk 无一命中 immutable 分支,全部落到兜底 no-store。

改动

  • 放宽判定正则 CONTENT_HASHED_ASSET_FILE_RE = /[-.][A-Za-z0-9_-]{8,}\.(?!html$)[A-Za-z0-9]{1,8}$/i:兼容 8~13 位 hash、-/. 两种分隔符,覆盖 js/css/wasm/字体/图片等,且显式排除 html(入口永远不固化)。
  • 新增回归测试:12 位 hash 的 JS/WASM 仍 immutable;固定名(无 hash)资源维持 no-store。

验证(241.t 真机)

部署后对入口 HTML 引用的全部静态资源做 curl 巡检:

  • official-patched-v8/assets/index-*.js / assets/*.css → public, max-age=31536000, immutable ✅
  • assets/*.woff2 / *.webp 等 → public, max-age=31536000, immutable ✅
  • /、/codex-web-config.js、/api/* 等动态入口 → 维持 no-store / private, no-cache, must-revalidate ✅
  • 全量单测通过(缓存相关 50/50,仓库既有 6 个与本改动无关的失败保持不变)。

附注

  • 241.t 部署时额外发现:2.1.0 的 run-gateway.cjs 不再内置 --headless --disable-gpu,在无 GPU 的无头服务器上 Chromium GPU 进程 FATAL 会拖垮 gateway。这属于部署环境适配,已在 241.t 本地 runner 处理,未纳入本 PR(避免扩大改动面)。
  • /official/ 裸路径访问返回 500(EISDIR),是 2.0.3/2.1.0 都存在的独立既有问题,与本改动无关。

Rolldown switched official bundle content hashes from 8 to 12 chars, so the hardcoded {8} immutable-asset pattern no longer matched and every hashed chunk fell through to no-store. Widen the pattern to 8+ chars with dash or dot separators, and strip auth cookie refresh from public long-cache responses so browsers can reuse them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants