Chrome refused to execute this JavaScript file

Posted by TestSubject528491 on Pro Webmasters See other posts from Pro Webmasters or by TestSubject528491
Published on 2013-06-25T01:58:48Z Indexed on 2013/06/26 4:29 UTC
Read the original article Hit count: 257

Filed under:
|
|

In the head of my HTML page, I have:

<script src="https://raw.github.com/cloudhead/less.js/master/dist/less-1.3.3.js"></script>

When I load the page in my browser (Google Chrome v 27.0.1453.116) and enable the developer tools, it says:

Refused to execute script from 'https://raw.github.com/cloudhead/less.js/master/dist/less-1.3.3.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

Indeed, the script won't run. Why does Chrome think this is a plain text file? It clearly has a .js file extension.

Since I'm using HTML5, I omitted the type attribute, so I thought that might be causing the problem. So I added type="text/javascript" to the <script> tag, and got the same result. I even tried type="application/javascript" and still got the same error.

Then I tried changing it to type="text/plain" just out of curiosity. The browser did not return an error, but of course the JavaScript did not run either.

Finally I thought the periods in the filename might be throwing the browser off. So in my HTML code, I changed all the periods to the URL escape character %2E:

<script src="https://raw.github.com/cloudhead/less%2Ejs/master/dist/less-1%2E3%2E3.js"></script>

This still did not work. The only thing that truly works (i.e. the browser does not give an error and the JS successfully runs) is if I download the file, upload it to a local directory, and then change the src value to the local file. I'd rather not do this since I'm trying to save space on my own website.

How do I get Chrome to recognize that the linked file is actually a JavaScript type?

© Pro Webmasters or respective owner

Related posts about JavaScript

Related posts about html5