有用户跟我说我的博客好特么慢,根本进不去!一直卡那个正方形转圈加载动画。
经过简单分析就不难发现,是butterfuly自带的默认npm资源CDN太慢了。

那么只需要更换一个国内访问快的就可以解决这个问题
先去主题配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
CDN:
# The CDN provider for internal and third-party scripts
# Options for both: local/jsdelivr/unpkg/cdnjs/custom
# Note: Dev version can only use 'local' for internal scripts
# Note: When setting third-party scripts to 'local', you need to install hexo-butterfly-extjs
internal_provider: local
third_party_provider: custom

# Add version number to url, true or false
version: false

# Custom format
# For example: https://cdn.staticfile.org/${cdnjs_name}/${version}/${min_cdnjs_file}
custom_format:

third_party_provider字段的值改成custom,上面是一个已经改好的效果

然后就是配置custom_format
我在Twikoo官群里交流得到有如下两个可选项:
1.https://registry.npmmirror.com/${cdnjs_name}/${version}/files/${min_cdnjs_file}
2.https://cdn.jsdmirror.com/npm/${name}@${version}/${min_file}

当然了,选项1的写法也可以换成https://registry.npmmirror.com/${name}/${version}/files/${min_file},效果相同。
但是选项1的有缺点
大量库加载失败
那就是有白名单机制,registry.npmmirror.com是淘宝的镜像,为了避免被当网盘所以加了白名单限制,详见https://www.yuque.com/egg/cnpm/files
即引用的包需要在https://github.com/cnpm/unpkg-white-list 中存在。

并且,有些包还需要区分dist不dist。而custom_format规则只能填写一个通配
例如
不能直接引入https://registry.npmmirror.com/aplayer/1.10.1/files/APlayer.min.css
而是需要https://registry.npmmirror.com/aplayer/1.10.1/files/dist/APlayer.min.css

因此本文推荐选项2配置项。
因为修改了配置项,所以别忘了用一次hexo clhexo g来重新生成以更新框架