ZoyaPatel

[Git 教程] GitHub Raw 文件链接获取及 jsDelivr CDN 使用指南

SohaniSharma

 

在 GitHub 上查看文件的 Raw(原始)视图,可以直接看到文件的纯文本内容,通常用于复制文件内容或用于其他程序访问。{alertInfo}

{getToc} $title={Table of Contents}

如何在 GitHub 上打开 Raw 视图:

打开你想查看的文件页面(例如一个 .html.js.md 文件)。

在文件内容展示区的右上角,点击 “Raw” 按钮。这个按钮通常位于 “Blame”、“History”等按钮旁边。

点击后,GitHub 会跳转到该文件的原始文本地址,URL 类似于:

https://raw.githubusercontent.com/用户名/仓库名/分支名/文件路径

示例:

如果你在浏览这个文件:

https://github.com/octocat/Hello-World/blob/main/README.md

点击 Raw 后会跳转到:

https://raw.githubusercontent.com/octocat/Hello-World/main/README.md

你可以将这个 Raw 链接复制到其他地方,如 curl wget 下载或在网页 <script src="..."> 中引用 JavaScript 文件。

某些脚本工具、CDN 服务(如 jsDelivr)可以将 GitHub 仓库文件转换为 CDN 链接,避免被 GitHub 限速。

注意 有的时候地址会变为内部稳定的某些地址:ref/head/。{alertWarning}

raw.githubusercontent.com/xykt/NetQuality/refs/heads/main/ref/speedtest_cn.json

实际的地址:

raw.githubusercontent.com/xykt/NetQuality/main/ref/speedtest_cn.json

删掉后,就可以找到源地址。

jsDelivr

官网: https://www.jsdelivr.com/

用途: 将 GitHub、npm、WordPress 插件等文件通过 CDN 加速。

用法(GitHub)

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

示例

https://github.com/username/repo/blob/main/script.js
jsDelivr CDN:
https://cdn.jsdelivr.net/gh/username/repo@main/script.js

说明

支持自动缓存、全球加速。@main 表示分支,也可指定 tag 或 commit hash。

举个例子:

NetQuality/ref/speedtest_cn.json at main · xykt/NetQuality

点击文件Raw 就可以跳转到下面

raw.githubusercontent.com/xykt/NetQuality/refs/heads/main/ref/speedtest_cn.json

实际地址,手动修改为:

raw.githubusercontent.com/xykt/NetQuality/main/ref/speedtest_cn.json

CDN 极速的地址

https://cdn.jsdelivr.net/gh/xykt/NetQuality@main/ref/speedtest_cn.json

补充:

github.com/user/repo/raw/branch/file

这是 GitHub 的 网页跳转 URL,并不是直接的原始内容链接。

手动在浏览器中打开查看文件内容。它会跳转(302)到

raw.githubusercontent.com

进行实际下载。

版权声明:
感谢您的阅读,除非文中已经注明来源网站,否则均为理科生网原创内容,转载时请务必以超链接(而非纯文本链接)标注来源于理科生网及本文完整链接,感谢!
{alertInfo}
Ahmedabad
Kolkata
Hyderabad
后一页 Bangalore 前一页

Random Manga

Ads

نموذج الاتصال