Ionică Bizău Ionică Bizău - 9 months ago 122
Javascript Question

Hotlink resources like JavaScript files directly from GitHub

I asked a question about including resources from GitHub and the answer was to use the raw link:

I am trying to include a script using:


but I get the following error:

Refused to execute script from '' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

Are there any alternatives to fix this error?

Usage example

I don't use this in the production but for a demo page:

├─ master
│ ├─ src
│ │ └─ my-jQuery-plugin.js
│ └─
└─ gh-pages
├─ css
│ └─ style.css
└─ index.html

In the index.html page I want to have the latest build of my-jQuery-plugin.js. So, I would include the raw URL to the script.

How do I fix the error?


Yes, Github changed this in April, 2013:

We added the X-Content-Type-Options: nosniff header 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 the Content-Type header. That means that when we set Content-Type: text/plain for raw views of files, the browser will refuse to treat that file as JavaScript or CSS.

But thanks to we can include GH scripts. The only change is to remove the dot from that becomes


The project is hosted on Github being open-source.

And yes, @Lix is correct. The files are not being served from Github but from the rawgit site.

Another workaround I found is that instead of:


you can use $.getScript jQuery function:

  $.getScript("", function () {
    /* do something when loaded */