Git Product home page Git Product logo

cdn's Introduction

CDN

使用 Github,jsDelivr, TravisCI 搭建一个轻量靠谱的 CDN。

实现原理

Github 做 CDN 存储,jsDelivr 做 CDN 服务器, TravisCI 做自动更新。

流程

  1. 本地添加文件到 Git,推送到 Github,触发 TravisCI 执行构建;
  2. TravisCI 拉取最新 Github 文件,打 Tag,发布到 Github Release, 将新版本文件推送回 Github;
  3. 用户访问 jsDelivr 的 CDN 服务器,jsDelivr 到 Github Release 拉取对应版本或者最新版本文件,返回给用户;
  4. 本地更新文件,如此往复触发第一步。

核心代码

language: node_js # 升级版本需要依赖 npm
node_js: stable

install: true # 无需安装依赖,调过安装

branches:
  only:
  - master # 只发布 master 分支

before_script:
- git config --global user.name "travis" # 配置 travis git 信息
- git config --global user.email "[email protected]"

script:
- git push -f https://[email protected]/$TRAVIS_REPO_SLUG.git `npm version patch -m "%s [ci skip]"` # 打 Tag,发布到 Github Release, 使用 [ci skip] 调过 CI, 防止死循环
- git push -f https://[email protected]/$TRAVIS_REPO_SLUG.git HEAD:master #将新版本文件推送回 Github

CDN 效果

文件地址: https://cdn.jsdelivr.net/gh/uuk/cdn/[folder]/[filename].[ext]

jsDelivr 服务器分布,有服务器位于**。

jsDelivr

文件浏览和流量统计

jsDelivr 提供了一个可以看 CDN 文件和使用流量的地址:https://www.jsdelivr.com/package/gh/uuk/cdn

演示

  1. https://cdn.jsdelivr.net/gh/uuk/cdn/pdf/bash中文文档.pdf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.