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

JavascriptHtmlGoogle ChromeMime Types

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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!

Solution 2 - Javascript

I tried fixing this problem using this method but it didn't work for me.

My problem was that IIS manager didn't have MIME types in HTTP Features.

I was able to turn it on by enabling Static Context via...

--> Control Panel

--> Programs

--> Turn Windows features on or off

--> Internet Information Services

--> World Wide Web Services

--> Common HTTP features

--> [X] Static Content.

After this, MIME types appeared and everything started working again.

Solution 3 - Javascript

The accepted answer is a great one! However, just to post an answer for those who encounter problem like me, who use a department/college computer sometimes, where I do not have the permission to change any key value in regedit.

Change

<script type="text/javascript" src="main.js"></script>

to

<script src="main.js"></script>

Although the error message still exist, the page loaded correctly.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbatzkooView Question on Stackoverflow
Solution 1 - JavascriptSimon SarrisView Answer on Stackoverflow
Solution 2 - Javascriptuser2383049View Answer on Stackoverflow
Solution 3 - JavascriptRichard WongView Answer on Stackoverflow