Link and execute external JavaScript file hosted on GitHub

前端 未结 15 845
感动是毒
感动是毒 2020-11-22 04:08

When I try to change the linked reference of a local JavaScript file to a GitHub raw version my test file stops working. The error is:

Refused to exe

相关标签:
15条回答
  • 2020-11-22 04:33

    Alternatively, if generating your markup server-side, you can just fetch and inject. For example, in JSTL you could do this:

    <script type="text/javascript">
        <c:import url="https://raw.github.com/mindmup/bootstrap-wysiwyg/master/bootstrap-wysiwyg.js" />
    </script>
    

    They don't allow hotlinking for a reason, so probably bad form if you want to be a good citizen. I'd suggest you cache that javascript and only actually re-fetch periodically as you see fit.

    0 讨论(0)
  • 2020-11-22 04:36

    When a file is uploaded to github you can use it as external source or free hosting. Troy Alford has explained it well above. But to make it easier let me tell you some easy steps then you can use a github raw file in your site:

    Here is your file's link:

    https://raw.githubusercontent.com/mindmup/bootstrap-wysiwyg/master/bootstrap-wysiwyg.js

    Now to execute it you have to remove https:// and the dot( . ) between raw and githubusercontent

    Like this:

    rawgithubusercontent.com/mindmup/bootstrap-wysiwyg/master/bootstrap-wysiwyg.js

    Now when you will visit this link you will get a link that can be used to call your javascript:

    Here is the final link:

    https://rawgit.com/mindmup/bootstrap-wysiwyg/master/bootstrap-wysiwyg.js

    Similarly if you host a css file you have to do it as mentioned above. It is the easiest way to get simple link to call your external css or javascript file hosted on github.

    I hope this is helpful.

    Referance URL: http://101helper.blogspot.com/2015/11/store-blogger-codes-on-github-boost-blogger-speed.html

    0 讨论(0)
  • 2020-11-22 04:36

    I had the same issue as you, what I did is change to

    <script type="application/javascript" src="bootstrap-wysiwyg.js"></script>
    

    It works for me.

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