Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource interpreted as Stylesheet but transferred with MIME type text/javascript

I have created an application using MVC, Java Script, JQuery, Ajax. When I'm debugging using visual studio it works fine without any script errors. When I am hosting my application on IIS server, it shows console errors and my application styles are not working correctly. I have attached the error below.

Error : Resource interpreted as Stylesheet but transferred with MIME type text/javascript:

Image:

Console Error Message

like image 663
udayangana Avatar asked Jan 19 '17 06:01

udayangana


3 Answers

I had the exact same problem, cause by lines in my HTML in the following form:

<link rel="stylesheet" type="text/css" href="css/my_css_resource.css" />

The problem was fixed when I removed rel="stylesheet" from the tag.

like image 136
JohnG79 Avatar answered Oct 14 '22 18:10

JohnG79


I can't comment due to low rep but this is very important.

The answer that says:

"I had the exact same problem, cause by lines in my HTML in the following form:

<link rel="stylesheet" type="text/css" href="css/my_css_resource.css" />

The problem was fixed when I removed rel="stylesheet" from the tag."

Is HORRIBLY wrong. rel="stylesheet" tells the browser this is a css file. Without it the browser doesn't know what to do with the CSS file, and any design code in it will NOT be executed.

I have confirmed this by removing all occurrences of rel="stylesheet" from my html file: the result was a completely "naked" page, with absolutely no design whatsoever. I have linked both bootstrap css and my own non-empty css, and tested it prior to removing rel="stylesheet" to see that style is actually modified by them.

Mime types are set by the sender of the file, in this case a web server. The error message says that a file sent as plain text by the server, was interpreted as CSS by the browser. In this case the problem is in the server, not in the browser. The browser correctly interpreted this CSS file as a stylesheet. The server should have sent the right mime type.

Again, I am sorry I am posting this as an answer even though it is not, but I can't post comments because of low rep. If a moderator is reading this and want's to remove it, please either post it as a comment to the relevant answer or if possible mark the answer as wrong so people will not suffer because of it.

like image 24
Hezi Yovel Avatar answered Oct 14 '22 17:10

Hezi Yovel


I realized that with my new Windows 10 machine, I'd failed to enable Static Content in my local IIS. To do so, go to "Turn Windows Features On or Off" from your Control Panel, and navigate to the following location:

enter image description here

Make sure this "Static Content" option is checked. Then, bring up a command window as an administrator and perform an iisreset.

Boom, fixed.

like image 4
Jason Marsell Avatar answered Oct 14 '22 17:10

Jason Marsell