如何从GitHub外部加载JavaScript文件? [英] How to load JavaScript files from GitHub externally?

查看:118
本文介绍了如何从GitHub外部加载JavaScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从raw.github.com加载JavaScript文件?此CSS代码非常有效:
< link rel = stylesheet type = text / css href = https://raw.github.com/myusername/myrepo/ master / style.css>

How can I load a JavaScript file from raw.github.com? This code for CSS works perfectly well: <link rel="stylesheet" type="text/css" href="https://raw.github.com/myusername/myrepo/master/style.css">

但不适用于JavaScript:
<脚本src = https://raw.github.com/myusername/myrepo/master/script.js>< / script>

But it will not work for JavaScript: <script src="https://raw.github.com/myusername/myrepo/master/script.js"></script>

推荐答案

您无法从Github加载JavaScript,因为内容类型不是 application / javascript text / javascript

You cannot load JavaScript from Github because the content type is not application/javascript or text/javascript.

这样做是有意防止您将Github用作CDN,这违反了他们的服务条款。

This is done intentionally to prevent you from using Github as a CDN, which is in violation of their terms of service.

另请参阅: https://rawgithub.com/

然后: https://github.com/blog/1482-heads-up-nosniff-header-support-coming-to-chrome-and-firefox

这篇关于如何从GitHub外部加载JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆