飘在云端

东西南北,海角天涯

· 备查 · · 290次浏览

cdn.jsdelivr.net CDN 具体使用细节

可能是我太菜了,这几天想临时给别人一个 GitHub 链接访问,因国内网络问题他无法打开,准备使用 cdn.jsdelivr.net 镜像之后的域名链接给他,测试时发现一直报找不到仓库 Couldn't find the requested file /xxx/xxxxx.blk in test/abc.

去官网 https://cdn.jsdelivr.net/ 看了下也没依葫芦画瓢成功,根据官网样例加其他搜索资料
我注意到一个细节
官方举例是

// load any GitHub release, commit, or branch

// note: we recommend using npm for projects that support it

https://cdn.jsdelivr.net/gh/user/repo@version/file


// load jQuery v3.6.4

https://cdn.jsdelivr.net/gh/jquery/jquery@3.6.4/dist/jquery.min.js


// use a version range instead of a specific version

https://cdn.jsdelivr.net/gh/jquery/jquery@3.6/dist/jquery.min.js

https://cdn.jsdelivr.net/gh/jquery/jquery@3/dist/jquery.min.js


// omit the version completely to get the latest one

// you should NOT use this in production

https://cdn.jsdelivr.net/gh/jquery/jquery/dist/jquery.min.js


// add ".min" to any JS/CSS file to get a minified version

// if one doesn't exist, we'll generate it for you

https://cdn.jsdelivr.net/gh/jquery/jquery@3.6.4/src/core.min.js


// add / at the end to get a directory listing

https://cdn.jsdelivr.net/gh/jquery/jquery/

上面中,默认省略了仓库分支,我推测可能默认使用 master 或者 main 来代替,只写了 @version 作为可选项

它的 jQuery 示例中,把 Tags作为版本号,我注意到 GitHub 是对 Tags 和 Branch 是并排显示的,此时合理推测这里应该是 关系,即 @version|Branch

最后拼接完毕,代理一个 GitHub 的链接完整形式应为

https://cdn.jsdelivr.net/gh/user/repo[@BranchName|@version]/file

翻译成人话:

https://cdn.jsdelivr.net/gh/用户名/仓库名[@分支名|@版本号]/路径/具体文件

示例:
原始链接:https://github.com/HuskyDG/MagiskHide/blob/scan/README.md
其 raw 链接:https://raw.githubusercontent.com/HuskyDG/MagiskHide/scan/README.md

仓库名后面跟的 blob 这个路径可以忽略,并不是实际路径,具体可以看这里解释

https://www.saoniuhuo.com/question/detail-2368234.html
https://geek-docs.com/git/git-questions/83_git_what_does_blob_in_github_correspond_to.html

可以看到这个 MagiskHidemasterscan 2个分支

js 镜像代理之后:https://cdn.jsdelivr.net/gh/HuskyDG/MagiskHide@scan/README.md

如果省略不写分支,应该会默认使用 master / main
这里测试默认不写,会访问 main 分支下的内容

https://cdn.jsdelivr.net/gh/HuskyDG/MagiskHide/README.md
评论 (0条)