Including JavaScript files from GitHub into HTML pages

后端 未结 7 846
北荒
北荒 2020-12-12 18:53

PAY ATTENTION!

You can\'t include Github scripts directly from Github after this change.

We added the X-Conte

相关标签:
7条回答
  • 2020-12-12 19:24

    rawgit looks like shutting down by end of 2019,

    some options for delivering content with with proper Content-Type headers.

    1. https://raw.githack.com/ , https://combinatronics.com=>exact alternative but it cannot be used for fetching from client side javascript, as cors is enabled here.
    2. jsdelivr =>for delivering javascript files
    0 讨论(0)
  • 2020-12-12 19:33

    You can include hosted CSS, HTML and JS file in GITHUB PAGES

    Just click at the settings on your github repository then at this tab scroll down to the GitHub Pages and select with the dropdown

    Then HOray you can now access it live

    This is the raw that returns text/plain mime type

    https://raw.githubusercontent.com/bdalina54/bdalina54.github.io/master/assets/js/terebra/acrior.js

    <script src="https://raw.githubusercontent.com/bdalina54/bdalina54.github.io/master/assets/js/terebra/acrior.js"></script>
    

    And this is the live version

    https://bdalina54.github.io/assets/js/terebra/acrior.js

    <script src="https://bdalina54.github.io/assets/js/terebra/acrior.js"></script>
    

    You can check my screenshot how I did it

    https://prnt.sc/obbrpn

    https://prnt.sc/obbt69

    https://prnt.sc/obbskb

    0 讨论(0)
  • 2020-12-12 19:38

    After enabling GitHub pages of your Repository, use following link:

    <script src="https://[username].github.io/[repository]/[filename].js"></script>
    
    0 讨论(0)
  • 2020-12-12 19:41

    This should work:

    <script src="https://raw.github.com/[username]/[repository]/[branch]/[filename].js"></script>
    

    Here is how you can get redirected to the needed address in github:

    enter image description here

    0 讨论(0)
  • 2020-12-12 19:43

    This works even with github's recent change:

    <script>
      $.getScript("https://raw.github.com/username/repo/master/src/script.js");
    </script>
    

    PS. requires jQuery.

    0 讨论(0)
  • 2020-12-12 19:48

    Try somethig like this:

    <html>
    <head>
        <script src="https://raw.github.com/e0ne/BlogSamples/master/ModalDialog/AdvancedPopup/jquery.min.js"></script>
    </head>
    

    It's working for me

    0 讨论(0)
提交回复
热议问题