hexo-theme-next icon indicating copy to clipboard operation
hexo-theme-next copied to clipboard

Static resource version control

Open ljcbaby opened this issue 2 years ago • 9 comments

Please follow this Issue template to provide relevant information, such as source code repository, website URL and screenshots, which will help us investigate. 请按照此 Issue 模版提供相关信息,例如源码仓库、网站链接和屏幕截图,这将有助于我们进行调查。

Issue Checklist

  • [x] I am using NexT version 8.0 or later.
  • [x] I have already read the relevant documents of Hexo and NexT.
  • [x] I have already searched for current issues, which does not help me.

Expected behavior

for static files load from local

like: css/style.css -> css/style.1234abcd.css

in _config.yaml

reversion: true  #default false

Other Information

Refer: 秒开的艺术:Hexo 博客首屏耗时优化实践 - 电脑星人

ljcbaby avatar Mar 17 '22 12:03 ljcbaby

Query string was removed in NexT v7.5.0 Relevant discussions: https://github.com/theme-next/hexo-theme-next/pull/963

stevenjoezhang avatar Apr 14 '22 17:04 stevenjoezhang

Version query string is not the best way to contral long-time cache.

For some CDN provider, request counts (not only http200, but all http codes) is also a billing item, so I think it can be better.

ljcbaby avatar Apr 14 '22 17:04 ljcbaby

乐特大佬几天前写了个插件 https://github.com/Lete114/Hexo-hash

MHuiG avatar May 11 '22 21:05 MHuiG

乐特大佬几天前写了个插件 https://github.com/Lete114/Hexo-hash

query string is not the best sloution.

ljcbaby avatar May 12 '22 01:05 ljcbaby

query string is not the best sloution.

css/style.1234abcd.css css/style.css?v=1234abcd

难道不一样吗,似乎没什么区别

MHuiG avatar May 12 '22 02:05 MHuiG

query string 可能加载的是 CDN 或者其他中间缓存的旧文件,但 style.1234abcd.css 一定能加载到新版本的文件

ljcbaby avatar May 12 '22 02:05 ljcbaby

query string 可能加载的是 CDN 或者其他中间缓存的旧文件,但 style.1234abcd.css 一定能加载到新版本的文件

有道理

MHuiG avatar May 12 '22 02:05 MHuiG

query string 可能加载的是 CDN 或者其他中间缓存的旧文件,但 style.1234abcd.css 一定能加载到新版本的文件

我模拟了一下CDN没有强制刷新缓存的情况,query string是请求到了旧文件,但是style.1234abcde.css 404了,因为没有这个文件

MHuiG avatar May 12 '22 04:05 MHuiG

我把这个功能加到 hexo-optimize 插件里面了: https://github.com/next-theme/hexo-optimize/commit/ab216ac4a67002a5dc3f99754eb7dec420a95b31 这样其它主题也可以用上。

另外,对于原文中提到的

在以下两种情况中,这一套缓存策略的表现不佳:

  • 在强制缓存的 max-age 时间内,服务器上的文件发生了变更,但浏览器仍然使用旧的文件(导致静态资源更新不及时,或多个静态资源之间有不一致)
  • 本地缓存过期,浏览器重新请求服务器,但服务器上的文件实际上没有发生变化。(需要耗费一次往返的时间才能确定本地缓存的静态资源可以使用)

我感觉这个影响其实不大。第一个情况,github.io 的 max-age 是 10 分钟,Netlify 是 0,我自己目前用的是 Cloudflare 的 rocker loader,则完全绕过了这个问题。因此,在真实情况下,用户遇到静态资源更新不及时的概率很低,如果启用了 Pjax 就更不会遇到了。 第二个情况,比较理想的方式是利用 HTTP/2 Server push 来解决。这个请求的开销有多大,对博客首屏耗时有多大影响,我没有找到实验数据支持。以后可以基于 hexo-optimize 做一些定量的 evaluation 和 ablation study 看看。

stevenjoezhang avatar Oct 28 '22 07:10 stevenjoezhang

事实上 Chrome 正准备在 Chrome 106 和其他基于 Chromium 的浏览器的下一个版本中删除 HTTP/2 Server push(

https://developer.chrome.com/en/blog/removing-push/ https://chromestatus.com/feature/6302414934114304 https://groups.google.com/a/chromium.org/g/blink-dev/c/K3rYLvmQUBY/m/vOWBKZGoAQAJ?pli=1

MHuiG avatar Oct 28 '22 07:10 MHuiG

是的,现在开始押宝 Early Hints 了: https://github.com/next-theme/hexo-theme-next/pull/577

stevenjoezhang avatar Oct 28 '22 07:10 stevenjoezhang

Server push 和 Cache-Digest 配合是可以完美解决情况二,但浏览器不支持的话,应该只能用本帖的方案来做了……

stevenjoezhang avatar Oct 28 '22 07:10 stevenjoezhang

[email protected] released

stevenjoezhang avatar Oct 29 '22 15:10 stevenjoezhang

This thread has been automatically locked since there has not been any recent activity after it was closed. It is possible issue was solved or at least outdated. Feel free to open new for related bugs.

github-actions[bot] avatar Oct 30 '23 00:10 github-actions[bot]