Skip to content

支持浏览器缓存#417

Closed
neveler wants to merge 4 commits intoHMCL-dev:mainfrom
neveler:cache
Closed

支持浏览器缓存#417
neveler wants to merge 4 commits intoHMCL-dev:mainfrom
neveler:cache

Conversation

@neveler
Copy link
Contributor

@neveler neveler commented Mar 10, 2026

支持浏览器缓存

描述

通过为静态资源添加 hash 参数结合 service worker 实现浏览器端缓存。

改动

  1. main.css 不再用于主题的默认皮肤,默认皮肤的样式迁移至 default.css
  2. 优化 auto-link 插件,现在计算相对地址不再依赖 liquid
  3. 添加 hash_file 过滤器,用于计算目标文件的 hash {{ '/assets/js/demo.js' | hash_file }}
  4. 本地调试使用的 host 由 127.0.0.1 更改为 localhost
  5. 添加 service worker 用于缓存逻辑

https://cache-docs.hmcl.workers.dev


close #416

@neveler neveler marked this pull request as ready for review March 11, 2026 11:38
@burningtnt
Copy link
Member

一个 PR 请仅专注于一个特定的方面,不要夹杂大量更改,以免干扰 PR 审查

@huanghongxun
Copy link
Collaborator

感谢你的提交,但目前HMCL-docs的页面是会缓存的,我理解不需要使用 service worker 额外增加缓存。

@neveler
Copy link
Contributor Author

neveler commented Mar 17, 2026

感谢你的提交,但目前HMCL-docs的页面是会缓存的,我理解不需要使用 service worker 额外增加缓存。

该 PR 所采用的方案,确实可以借助 service worker,在 HTML 内容未发生变化的情况下避免额外的服务器请求。但与此同时,这一实现需要引入了基于 Ruby 的自定义插件为静态资源计算 hash,从而在一定程度上增加了系统复杂度并降低了整体可维护性。

最初考虑在浏览器端引入缓存机制,是由于境外访问文档站时,在切换皮肤时往往需要等待较长时间才能生效,因此才探索通过 service worker 优化体验。

另外,想进一步确认一下:后续是否有为文档站引入 CDN 的规划?如果有,这类问题或许可以通过 CDN 更直接地得到缓解。

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.

支持浏览器缓存

3 participants