How to link files directly from Github (raw.github.com)

后端 未结 10 2152
耶瑟儿~
耶瑟儿~ 2020-11-30 19:52

Are we allowed to link files directly from Github ?



        
相关标签:
10条回答
  • 2020-11-30 20:33

    Add a branch your project using the name "gh-pages" and then you'll (shortly after branching) be able to use a direct URL such as https://username.github.io/project/master/style.css (using your URL, and assuming "style.css" is a file in the "master" folder in the root of your "project" repository...and that your Github account is "username").

    0 讨论(0)
  • 2020-11-30 20:37

    GitHub Pages: https://yourusername.github.io/script.js
    GitHub repo raw files: https://github.com/yourusername/yourusername.github.io/blob/master/script.js

    Use GitHub Pages, DO NOT use raw files.

    Reason: GitHub Pages are based on CDN, raw files are not. Accessing raw files will directly hit on GitHub servers and increase server load.

    0 讨论(0)
  • 2020-11-30 20:39

    You need carry out the following steps

    1. Get the raw url of the file from github. Which is something like https://raw.githubusercontent.com/username/folder/example.css

    2. Visit http://rawgit.com/. Paste the git url above in the input box. It will generate two url's, one for development and other for production purpose.

    3. Copy any one of them and you are done.

    The file will act as a CDN. You can also use gist urls.

    0 讨论(0)
  • 2020-11-30 20:41

    Use jsdelivr.com

    Copied directly from https://www.jsdelivr.com/?docs=gh:

    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 讨论(0)
提交回复
热议问题