加速 Hexo 博客

利用 InstantClick、hexo-service-worker、hexo-filter-optimize 让博客快如闪电 zap

speed-up-hexo.png

先体验:https://yixiuer.me/ ,然后操作 dolphin ~

根据读者们反馈,使用后可能会有各种问题,如自己难以解决,请暂时先勿使用!

文章待更新!

InstantClick

介绍请看官网:http://instantclick.io/ ,先下载压缩版的 instantclick.min.js(浏览器右键保存为),再放到~/blog/themes/next/source/js/src/下,然后添加代码:

文件位置:~/blog/themes/next/layout/_layout.swig
1
2
3
4
+ <script type="text/javascript" src= "/js/src/instantclick.min.js" data-no-instant></script>
+ <script data-no-instant>InstantClick.init();</script>
</body>
</html>

去除顶部加载条:

文件位置:~/blog/themes/next/source/css/_custom/custom.styl
1
2
3
#instantclick {
display: none;
}

可能会有一些问题,比如与 FancyBox、Google Analytics 等等的兼容问题,解决方法自行查看文档或 Google。

Hexo 插件

主要利用两个插件:

  1. hexo-service-worker
  2. hexo-filter-optimize

先在站点文件夹根目录安装:

所在目录:~/blog/
1
npm install hexo-service-worker hexo-filter-optimize --save

然后在站点配置文件中配置:

文件位置:~/blog/_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# offline config passed to sw-precache.
service_worker:
maximumFileSizeToCacheInBytes: 5242880
staticFileGlobs:
- public/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff,woff2}
stripPrefix: public
verbose: true

filter_optimize:
enable: true
# remove static resource query string
# - like `?v=1.0.0`
remove_query_string: true
# remove the surrounding comments in each of the bundled files
remove_comments: true
css:
enable: true
# bundle loaded css file into the one
bundle: true
# use a script block to load css elements dynamically
delivery: true
# make specific css content inline into the html page
# - only support the full path
# - default is ['css/main.css']
inlines:
excludes:
js:
# bundle loaded js file into the one
bundle: true
excludes:
# set the priority of this plugin,
# lower means it will be executed first, default is 10
priority: 12

最后deploy到 GitHub 上查看效果,Enjoy it ! coffee ~


本文结束啦感谢您阅读
0%