-
新建Github\cdn仓库
命名为cdn,公开访问权限
获取仓库地址
-
克隆仓库到本地
在本地目录右键 Git Bash Here,执行以下命令:git clone https://github.com/rdstwg/cdn.git
第一次应该是空目录,以后有素材文件,这一步就比较关键(以免替覆盖掉之前的素材)
-
上传资源
现有img和js素材,复制到cdn目录下(支持20M以内的图片、视频、js、css等)
在本地git仓库目录下右键 Git Bash Here,执行以下命令:git status //查看状态
git add . //添加所有文件到暂存区
git commit -m '第一次提交' //把文件提交到仓库
git push //推送至远程仓库
也可以用Git Gui上传,上传成功后在浏览器可查看https://github.com/cungudafa/cdn
-
发布资源
点击release自定义发布的版本号
三、jsDelivr引用
原理:将github上的资源转为快速访问网址
例如:
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/img/re.png
版本号不是必需的,是为了区分新旧资源,如果不使用版本号,将会直接引用最新资源
//完全省略该版本以获取最新版本
https://cdn.jsdelivr.net/gh/user/repo/file
https://cdn.jsdelivr.net/gh/cungudafa/cdn/img/rdstwg/re.jpg
其他资源填写路径即可:
// 加载任何Github发布、提交或分支
https://cdn.jsdelivr.net/gh/user/[email protected]/file
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/js/lib.min.js
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/img/custom/HanHyoJoo.gif
除此之外还可以使用某个范围内的版本,查看所有资源等,具体使用方法如下:
// 使用版本范围而不是特定版本
https://cdn.jsdelivr.net/gh/user/[email protected]/file
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/img/custom/re.png
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/img/custom/re.png
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/img/custom/re.png
压缩版
// 将“.min”添加到任何JS/CSS文件中以获取缩小版本,如果不存在,将为会自动生成
https://cdn.jsdelivr.net/gh/user/[email protected]/file/file.min.js
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/js/InsightSearch.js
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/js/InsightSearch.min.js
目录
// 在末尾添加 / 以获取资源目录列表
https://cdn.jsdelivr.net/gh/user/[email protected]/file/
https://cdn.jsdelivr.net/gh/rdstwg/[email protected]/img/custom/
版权声明:版权归 菜鸟 所有,转载请注明出处!
本文链接:http://vpsnoob.com/archives/11/
如果博客出现404或链接失效,请留言或者联系博主修复!