Javascript – Resource interpreted as Script but transferred with MIME type text/plain – for local file

google-chromehtmljavascriptmime-types

I'm getting a "Resource interpreted as Script but transferred with MIME type text/plain" warning in Google Chrome when including a local script file.

I know the problem appears when loading a file from a server or through ajax which most often depends on wrong headers being set.

The weird thing is that I get this warning even though it is run from a local folder: file:///C:/test/foo.html

This happens only in Chrome with the most basic html there is:

<!DOCTYPE html>
    <html>
    <head>
        <script type="text/javascript" src="bar.js"></script>
    </head>
    <body>
    </body>
</html>

bar.js is also as simple as it can get:

function hello() {}

I've tried adding a meta tag:

<meta http-equiv="content-script-type" content="text/javascript">

and tested with other doctypes but nothing seems to help.

This obviously isn't a real issue since the scripts still work fine, but I'm working on a large project and currently have around 150 scripts included. It therefore makes it difficult to see when an actual warning occurs in between them.

Everything works fine when I run the file on a server, locally or remote.

Any ideas on why chrome is annoying me with this?

Best Answer

I figured it out!

The Visual Studio installer must have added an errant line to the registry.

open up regedit and take a look at this registry key:

enter image description here

See that key? The Content Type key? change its value from text/plain to text/javascript.

Finally chrome can breathe easy again.

I should note that neither Content Type nor PercievedType are there by default on Windows 7, so you could probably safely delete them both, but the minimum you need to do is that edit.

Anyway I hope this fixes it for you too!