hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.48k stars 4.86k forks source link

Do it have the way for Revisioning (Add a hash to filename)? #3042

Closed vimcaw closed 6 years ago

vimcaw commented 6 years ago

I use hexo to make my blog and make a theme updated frequently. Although I set no-cache on cache-control, Chrome still caches my site file. After updating CSS and JS file and deploying, GitHub repo has updated, but my site still uses the old file for a long time. After I clear cache, it uses the new file, but I can't tell my visitor clear cache every time, right? I search some info and find Chrome will force cache site file. One solution is to add the md5 of the file to the filename. Such as main?75f329868c94e5df.js I search the plugin to do it for a long time but finding nothing can do it. I try to make a plugin, but hexo-fs can't rename a file.

ertrzyiks commented 6 years ago

I'm looking for the same thing. Found this plugin and it uses route.set to generate hashed filenames

https://github.com/hexojs/hexo-asset-pipeline/blob/5b4527b839aca380f61419536f89ac138b9eb357/lib/revision.js#L113

Unfortunately, the plugin doesn't fully work for me (I use the latest hexo version), but it may be a good direction.

vimcaw commented 6 years ago

@ertrzyiks Thanks! It's exciting plugin! But it turned my href attribute into \undefined after I enable it. Maybe I can fix this.

ertrzyiks commented 6 years ago

@vimcaw yes, it generates '/undefined' for me too. Keep us posted if you manage to use it. I'm going to use some alternative approach (which I don't know yet)

vimcaw commented 6 years ago

@ertrzyiks I has found the reason which resulted in the bug and has partially fixed this, but it still has some bugs about asset-folders path. I believe I can fix it in recent days.

vimcaw commented 6 years ago

@ertrzyiks I has fixed this bug: V1.4.2 - Fixed: Revisioning turn src and href into undefined. \r\n- O… by vimcaw · Pull Request #15 · hexojs/hexo-asset-pipeline

ertrzyiks commented 6 years ago

@vimcaw excellent job! I'm only struggling with background-image inline styles now. Probably just exclude from revisioning. Thanks for doing this!

vimcaw commented 6 years ago

@ertrzyiks It still has some bugs in the relative path and revisioning sequence. A temporary solution is to add error paths to exclude list. I will try to fix them when I'm free.

vimcaw commented 6 years ago

There are 4 ways to achieve it:

  1. hexo-asset-pipeline Revisioning can achieve it.
  2. hexo-renderer-webpack can use webpack to easily achieve it.
  3. directly use webpack or gulp (commend to install at theme folder). first, webpack or gulp revision the files and output some files, then the themes use the outputed files.
  4. directly use webpack or gulp (commend to install at root folder). first, hexo generate the publish files, then webpack or gulp revision the files.