如何从外部从 GitHub 加载 JavaScript 文件

How to load JavaScript files from GitHub externally?

本文关键字:加载 JavaScript 文件 GitHub 从外部      更新时间:2023-09-26

如何从 raw.github.com 加载 JavaScript 文件?CSS的这段代码运行良好:

<link rel="stylesheet" type="text/css" href="https://raw.github.com/myusername/myrepo/master/style.css">

但它不适用于 JavaScript:

<script src="https://raw.github.com/myusername/myrepo/master/script.js"></script>

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

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

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

而这个:https://github.com/blog/1482-heads-up-nosniff-header-support-coming-to-chrome-and-firefox