快速免费的公用CDN

AI摘要:

jsDelivr

官网地址:jsDelivr - A free, fast, and reliable CDN for JS and open source 没梯子访问可能有点慢,不过CDN的节点是很快的 可以引用的资源包括NPM、github、wordpress的所有资源,github可以是任意体积小于50M的仓库。

以github为例,只需要通过符合 JSDelivr 规则的 URL 引用,即可直接使用 Github 中的资源。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 用户名/仓库名@版本号/文件名
https://cdn.jsdelivr.net/gh/user/repo@version/file
// load jQuery v3.2.1
https://cdn.jsdelivr.net/gh/jquery/jquery@3.2.1/dist/jquery.min.js


// 使用一个范围内的版本
https://cdn.jsdelivr.net/gh/jquery/jquery@3.2/dist/jquery.min.js
https://cdn.jsdelivr.net/gh/jquery/jquery@3/dist/jquery.min.js


// 忽略版本号则默认使用最新版
// you should NOT use this in production
https://cdn.jsdelivr.net/gh/jquery/jquery/dist/jquery.min.js


// 在任意JS/CSS文件后添加 .min 能得到一个缩小版
// 如果它本身不存在,我们将会为你生成
https://cdn.jsdelivr.net/gh/jquery/jquery@3.2.1/src/core.min.js


// 在末尾加 / 则得到目录列表
https://cdn.jsdelivr.net/gh/jquery/jquery/

详细规则参考官网:jsDelivr - A free, fast, and reliable CDN for JS and open source

以我一张图片为例:

原github链接:https://raw.githubusercontent.com/growvv/img/master/images/20200118222911.jpeg

CDN后的链接:https://cdn.jsdelivr.net/gh/growvv/img@master/images/20200118222911.jpeg

unpkg

unpkg是一个内容源自npm的全球快速CDN。它部署在 cloudflare上,在大陆地区访问到的是香港节点。

比如我们网页需要加载jquery的版本2.1.4时,我们可以写成:

1
2
https://cdn.jsdelivr.net/npm/jquery@2.1.4/dist/jquery.min.js
1

或者

1
https://unpkg.com/jquery@2.1.4/dist/jquery.min.js

其他

除了jsdelivr, 推荐几个免费的且不限流量的CDN,还有 staticaly githack 都是全球通用的,

staticaly

官网地址:The CDN for Static Files on GitHub, GitLab, and Bitbucket - Statically
轻松地从GitHub / GitLab / Bitbucket等加载您的项目 没有流量限制或限制。

文件通过超快速全球CDN提供。 在URL(不是分支)中使用特定标记或提交哈希。
根据URL永久缓存文件。 除master分支外,文件在浏览器中缓存1年。 具体用法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# GitHub CDN
https://cdn.staticaly.com/gh/:user/:repo/:tag/:file
https://cdn.staticaly.com/gh/growvv/growvv.github.io/master/README.md

# GitLab CDN
https://cdn.staticaly.com/gl/:user/:repo/:tag/:file

# Bitbucket CDN
https://cdn.staticaly.com/bb/:user/:repo/:tag/:file

# WordPress CDN
https://cdn.staticaly.com/wp/c/:version/wp-includes/:file
https://cdn.staticaly.com/wp/p/:plugin_name/:version/:file
https://cdn.staticaly.com/wp/t/:theme_name/:version/:file

# Imgpx CDN
https://cdn.staticaly.com/img/:image_url

# Favicons CDN
https://cdn.staticaly.com/favicons/:favicon_url

githack

直接从GitHub,Bitbucket或GitLab提供原始文件
官网地址:https://raw.githack.com/ 具体用法和上面的staticaly很类似

1
2
3
4
5
6
# Github CDN
//主分支
https://rawcdn.githack.com/liub1934/LB-Blog/master/wp-content/themes/Memory/emoji/xiaodianshi/baiyan.png

//版本分支
https://rawcdn.githack.com/liub1934/LB-Blog/8806f440d3f9a7cc3e6125d7d75564e40262c6a8/wp-content/themes/Memory/emoji/xiaodianshi/baiyan.png

快速免费的公用CDN
https://blog.cngo.rr.nu/posts/1db4.html
作者
cngo
发布于
2024年7月8日
许可协议