Skip to content

fix: 部署加资源哈希防缓存错配 + 首页语言按钮图标对齐 - #58

Merged
Vincentwei1021 merged 2 commits into
mainfrom
fix/gallery-asset-cache-bust
Aug 28, 2026
Merged

fix: 部署加资源哈希防缓存错配 + 首页语言按钮图标对齐#58
Vincentwei1021 merged 2 commits into
mainfrom
fix/gallery-asset-cache-bust

Conversation

@Vincentwei1021

@Vincentwei1021 Vincentwei1021 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

两个线上小毛病,一起修。

1. 新 HTML 配旧样式(缓存错配)

现象:PR #57 部署完成后,线上 library 页样式崩掉:关注面板行堆叠、图标撑满整列、链接带下划线,顶栏两个 toggle 的图标变成大黑圆。

根因:不是没部署——线上 styles.css 抓下来是新的(.topbar-toggle / .follow-row / .link-arrow 都在)。GitHub Pages 给静态资源发 cache-control: max-age=600,而 HTML 里引用 css/js 没有版本号,所以部署后十分钟窗口里浏览器用缓存里的旧 styles.css 渲染了新 HTML:新类名在旧 CSS 里没有规则,SVG 失去尺寸约束、<a> 没去下划线、flex 失效变堆叠。硬刷即恢复,但每次改 gallery 都有这个窗口。

改法:deploy-pages 装配后加一步 stamp,按文件内容 md5 前 8 位改写 site/*.html 的资源引用。

<link rel="stylesheet" href="./styles.css?v=529cd0d0">
<script src="./translations.js?v=052e9472" defer></script>
<script src="./app.js?v=e86bfc86" defer></script>
  • 每个 HTML 版本只引用自己那一代资源 URL,新 HTML 请求的 URL 浏览器没缓存过,必然拉新文件。
  • 哈希不变则 URL 不变,照旧命中浏览器缓存。
  • 只作用于部署产物(site/),仓库里的 gallery/ 与本地预览不受影响,无需手工维护版本号。

2. 首页语言按钮图标与文字不在一条水平线上

图标外壳 span 默认 display: block,15px 的 svg 贴在 19.5px 行高盒顶部,中线比文字高 2.3px(线上实测 svg 36.3 / 文字 38.6)。补上 .language-toggle-icon { display: inline-flex } 后两者中线都是 38.6。

library / showcase 的 .topbar-toggle-icon 本来就有这条规则,实测 delta 0,是我在首页那份内联 CSS 里漏了。

实测

  • 按 workflow 的 rsync 规则在本地装配 site/ 跑同一段 stamp 脚本:library 打 3 个链接、showcase 打 2 个,起 http 服务确认引用生效;workflow YAML 过 yaml.safe_load
  • 首页对齐用 Playwright 量 getBoundingClientRect 中线:修前 delta 2.3px,修后 0。

🤖 Generated with Claude Code

Vincentwei1021 and others added 2 commits August 28, 2026 22:17
Pages 对静态资源发 cache-control: max-age=600,PR #57 部署后十分钟窗口里
浏览器拿旧 styles.css 配新 library.html,侧栏关注面板和顶栏 toggle 全崩
(图标撑满、行堆叠、链接带下划线)。装配后加一步 stamp:按文件内容 md5
前 8 位改写 site/*.html 里 styles.css / app.js / showcase.js /
translations.js 的引用,每个 HTML 版本只引用自己那代资源,哈希不变则沿用
浏览器缓存。只作用于部署产物,仓库内的 gallery/ 与本地预览不受影响。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
图标外壳 span 默认 display:block,svg 贴在 19.5px 行高盒顶部,中线比文字
高 2.3px(线上实测 svg 36.3 / 文字 38.6)。补 .language-toggle-icon
inline-flex 后两者中线都是 38.6,delta 0。library/showcase 的
.topbar-toggle-icon 本来就有这条规则,实测 delta 0,不受影响。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Vincentwei1021 Vincentwei1021 changed the title fix(deploy): 部署时给 css/js 链接打内容哈希 ?v=,堵住新 HTML 配旧样式 fix: 部署加资源哈希防缓存错配 + 首页语言按钮图标对齐 Aug 28, 2026
@Vincentwei1021
Vincentwei1021 merged commit b0cb891 into main Aug 28, 2026
3 checks passed
@Vincentwei1021
Vincentwei1021 deleted the fix/gallery-asset-cache-bust branch August 28, 2026 14:28
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.

1 participant