PAY ATTENTION!
You can’t include Github scripts directly from Github after this change.
We added the
X-Content-Type-Options: nosniffheader to our raw URL responses way back in 2011 as a first step in combating hotlinking. This has the effect of forcing the browser to treat content in accordance with theContent-Typeheader. That means that when we setContent-Type: text/plainfor raw views of files, the browser will refuse to treat that file as JavaScript or CSS.But there are alternatives. Check my answer to this question.
I am trying to include a JavaScript file from GitHub into a local HTML file for testing (like an image found on the internet: <img src="http://...">).
I would like something like this:
<script src="https://github.com/[username]/[repository]/blob/master/public/[fileName].js"></script>
The problem is that this doesn’t work.
How can I do this?
https://rawgit.com has been shut down. This answer is unfortunately no longer relevant.
You will be able to do it with a URL similar to this:
Note that this is not the same as clicking on the "raw" button within GitHub;
that button will also give you a clean version of the file, but it will be sent
with the wrong headers.
A Word of warning; the file is not not being served from GitHub. It is being
redirected through the
rawgit.comdomain. As is stated on https://rawgit.com:Keep in mind that the owner of that domain is now in control of the traffic and
is able to manipulate it as they see fit.