jsDelivr - 开源项目CDN首选
官网: jsDelivr
特点:
- 支持NPM、GitHub、WordPress资源
- 单文件体积限制<50MB
- 全球CDN加速
GitHub资源引用格式:
1
| https://cdn.jsdelivr.net/gh/user/repo@version/file
|
实用技巧:
- 自动压缩: 在JS/CSS文件后加
.min
- 目录查看: URL末尾加
/
- 版本控制: 支持语义化版本范围
示例:
1 2
| https://cdn.jsdelivr.net/gh/jquery/jquery@3.2.1/dist/jquery.min.js https://cdn.jsdelivr.net/gh/growvv/img@master/images/20200118222911.jpeg
|
以图片为例:
原github链接:https://raw.githubusercontent.com/growvv/img/master/images/20200118222911.jpeg
CDN后的链接:https://cdn.jsdelivr.net/gh/growvv/img@master/images/20200118222911.jpeg
unpkg - npm生态专用CDN
特点:
- 专为npm包设计
- Cloudflare全球节点(亚洲用户访问香港节点)
示例:
1
| https://unpkg.com/jquery@2.1.4/dist/jquery.min.js
|
其他
除了jsdelivr
, 推荐几个免费的且不限流量的CDN,还有 staticaly
githack
都是全球通用的,
Statically - 多平台支持
官网: Statically
支持平台:
- GitHub/GitLab/Bitbucket
- WordPress插件/主题
- 图片代理
引用格式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| https://cdn.staticaly.com/gh/:user/:repo/:tag/:file https://cdn.staticaly.com/gh/growvv/growvv.github.io/master/README.md
https://cdn.staticaly.com/gl/:user/:repo/:tag/:file
https://cdn.staticaly.com/bb/:user/:repo/:tag/:file
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
https://cdn.staticaly.com/img/:image_url
https://cdn.staticaly.com/favicons/:favicon_url
|
GitHack - 原始文件直连
官网: GitHack
特点:
- 直接提供原始文件
- 支持GitHub/Bitbucket/GitLab
示例:
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
|
提示: 生产环境建议指定具体版本号,避免使用latest获取最新版本可能导致的兼容性问题。