How to Use jsDelivr CDN
博客上用了很多js和css,如果都通过服务器加载,加载速度会很慢(一开始我用这个主题,GithubPages托管的时候,第一次加载用来40s+)。所以需要把js和css文件放到CDN上。
我知道的公共CDN有BootCDN和JSDELIVR。
jsdelivr可以直接加载github上的文件,bootcdn不行。
我原来使用的是BootCDN,但是这玩意比jsdelivr慢,并且只能用官方的库,所以改用了jsdelivr。
jsdelivr的加载方法
Github
一言蔽之,就是https://cdn.jsdelivr.net/gh/用户名称/仓库名称@版本号/目录。
详细版:
1 | |
npm
gh换成npm,没有用户名。其他不变。
1 | |
刷新CDN
把链接中的https://cdn.jsdelivr.net/换成https://purge.jsdelivr.net/就行了。
My blog uses many JS and CSS files. If they are all loaded through the server, the loading speed will be very slow (when I first used this theme hosted on GitHub Pages, the initial load took over 40 seconds). Therefore, it’s necessary to place JS and CSS files on a CDN.
The public CDNs I’m aware of are BootCDN and JSDELIVR.
jsDelivr can directly load files from GitHub, while BootCDN cannot.
I originally used BootCDN, but it’s slower than jsDelivr and only supports official libraries, so I switched to jsDelivr.
How to Load from jsDelivr
GitHub
In a nutshell, it’s https://cdn.jsdelivr.net/gh/username/repository@version/directory.
Detailed version:
1 | |
npm
Replace gh with npm, without a username. Everything else remains the same.
1 | |
Refreshing the CDN
Simply replace https://cdn.jsdelivr.net/ in the URL with https://purge.jsdelivr.net/.