Github + jsDelivr 免费CDN托管js和css文件

Github + jsDelivr 免费CDN托管js和css文件

一、 Github 操作:

  • 创建新仓库:“cdn”,勾选自动创建readme.md文件选项。
  • 复制仓库地址

二、 本地操作:

  • 创建本地文件夹,用来管理仓库
  • 进入文件夹,克隆仓库到本地,Git Bash Here:
1
git clone 粘贴Github仓库地址
  • 进入cdn文件夹,分别创建文件夹css和js。
  • 把自己的css和js文件分别放入对应文件夹。
  • Push文件到GitHub仓库,Git Bash Here:
1
2
3
4
git status
git add .
git commit -m 'first time'
git push

三、 GitHub 操作(若无需版本控制,此步骤可以省略):

  • 发布第一版 release:v1.0
  • 然后用 jsDelivr 规则引用即可使用

四、 jsDelivr 路径解释:

https://cdn.jsdelivr.net/gh/用户名/仓库名@版本号/文件路径

  • 例如:https://cdn.jsdelivr.net/gh/mygithubusername/cdn@v1.0/css/style.css
  • 用法:<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/mygithubusername/cdn@v1.0/css/style.css">
  • 若无版本号,‘@v1.0’ 删除

附:jsDelivr 规则:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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.2.1

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


// use a version range instead of a specific version

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


// 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.2.1/src/core.min.js


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

https://cdn.jsdelivr.net/gh/jquery/jquery/
-------------本文结束 感谢您的阅读-------------
转载别忘了注明出处哈
🍭🍭🍭😜
0%