Website CSS loading issue with IE and Edge - html

I have a website running perfectly fine on Chrome, Firefox, Safari etc. however, the CSS does not load in Internet explorer (any version) as well as in MS Edge browser.
The Console shows this infamous error related to MIME Type:
SEC7113: CSS was ignored due to mime type mismatch
File: application-2015-2a0565839ee60a029c49fc918e3625e9.css
SEC7113: CSS was ignored due to mime type mismatch
File: CustomCss.css
SEC7113: CSS was ignored due to mime type mismatch
File: print.css
I have checked in the code, and this is how it is in the <head>
// ASP.NET MVC code - .cshtml layout file
<link href='#Url.Content("/Content/application-2015-2a0565839ee60a029c49fc918e3625e9.css")' media="screen" rel="stylesheet" type="text/css"/>
<link href='#Url.Content("/Content/CustomCss.css")' media="screen" rel="stylesheet" type="text/css"/>
<link href='#Url.Content("/Content/2015/print.css")' media="print" rel="stylesheet" type="text/css"/>
I have checked in the IE Developer Tools, and the css indeed returned with incorrect MIME type (coming as blank) in IE instead of stylesheet or text/css as in Chrome or Firefox:
IE:
Chrome:
I have checked in IIS, the mime type for .css is mapped as expected:
How can I make IE to understand the Mime type and let it load it correctly.
Any help is highly appreciated.
EDIT
As suggested, also checked the Registry value for .css in HKEY_CLASSES_ROOT and this seems ok as below:
Also, ensured that no program is associated with CSS to open.

This is because under default settings, “static content” is not installed with IIS.
To enable this on a Windows Server 2008 machine do the following
Fire up Server Manager
Select Web Server under Roles – notice that Static Content is not installed
Select Add Role Services from the right hand menu
Check Static content and install
i think it works for you

It turns out that there was an HTTP Module which was the root cause of it as it turns out to be a known issue with ASP.NET, IIS and HTTP Module aas mentioned here:
ASP.NET CSS file not loaded when adding HttpModule to web.config
Following this and handling in Http Module explicitly for css, fixed this issue.
Thanks for everyone for taking time out and providing your expert comments

Looks like you've tried everything that seems to have worked for others.
Try setting the output to the mime type through the ASP.NET framework:
Response.ContentType = "text/css";
Have you tested using a load function?
Response.ContentType = "text/css"
Response.AddHeader("Header")
Response.WriteFile("CSS File.css")
Response.End()
Response.Clear()

You should check these things because if IE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
or
type="text/css" instead of type="css/stylesheet" when importing the stylesheet.

Related

I can't load my own CSS file when using Boostrap "MIME type ('text/html') is not a supported stylesheet MIME type"

I'm building a personal website, and I got an error in chrome that reads:
"Refused to apply style from 'http://localhost:3000/styles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled."
But everything seems to be linked just fine. I'm using Express, EJS, and Bootrap. I have this line in my Express:
app.use(express.static(__dirname + "/public/"));
And I linked my style sheelt like normal:
link rel="stylesheet" href="styles.css" type="text/css"
I don't know what could be causing this issue. I don't have anything inside of the actual css file, and it is in the main directory with everything else.
I think the css file is not found on your server so when your server searches for the css file and it doesn't finds it.It returns back with html MIME type.
You can also import your css file in App.js component
import './css/styles.css';
Or Just change 'href' to 'src'.
<link rel="stylesheet" href="./css/styles.css">
to this:
<link rel="stylesheet" src="./css/styles.css">

The stylesheet "path/to/font-awesome/css/font-awesome-min.css" didn't load because its MIME Type, text/html, is not text/css

I have a React App deployed with Heroku,
On Google Chrome, everythings works fine, but in Mozilla Firefox, I have the error in title :
The stylesheet "path/to/font-awesome/css/font-awesome-min.css" didn't load because its MIME Type, text/html, is not text/css
Here's the part involved in my index.html
<link
rel="stylesheet"
type="text/css"
href="/path/to/font-awesome/css/font-awesome.min.css"
/>
Do you know what I have to change please ?
"/path/to/font-awesome/css/font-awesome.min.css" is a placeholder that you need to change with the current path to font-awesome in your project.
It's different for each project, but if you installed with NPM maybe it's something like:
node_modules/font-awesome/css/font-awesome.min.css

What rel attribute should I use for css.map files?

In my web application I have some files with extension ".css.map".
Looking on the internet I see that, as content type, I should put "application/json" so my include directive looks like this:
<link rel="stylesheet" type="application/json" href="resources/css/angular-chart.css.map"/>
Nevertheless, this does not prevent my browser to display the warning:
Resource interpreted as Stylesheet but transferred with MIME type text/html
This warning seems to be the cause of a blank page displayed on internet explorer browser (chrome and firefox seem to be fine). After reloading the page IE does display it right, but I'd like to solve this problem at its root, by getting rid of that warning.
I think the problem is in the
rel="stylesheet"
so, what should I put there?
You shouldn't link to map files at all. Tools that use them will use a X-SourceMap header or infer the URL by adding .map to the URL of the actual stylesheet or JavaScript program.
Try explicitly specifying the type as json in your link tag, like so:
<link rel="stylesheet" type="application/json" href="blah">

Why dosen't this css file work

I was trying to host my css files on an cloud storage service but when I linked it to my website it was not executed,
so i created an small css which just changes background but yet it doesn't works.
It seems there is some problem with its server will you please tell me what could be the problem and how to use it as css
link of css file http://copy.com/Kgs8EaMF71Qa7zqo/style.css
HTML Code
<link href="http://copy.com/Kgs8EaMF71Qa7zqo/style.css" rel="stylesheet" type="text/css" />
https://developer.mozilla.org/en/docs/Incorrect_MIME_Type_for_CSS_Files
At least Gecko has a security feature for this: All stylesheets not from the same origin must be served with text/css.
In fact, you're file is served as text/plain, so the rules in it are ignored.
Due to security reasons MIME type of files hosted on copy.com is served as text/plain
So an normal link like of CSS file from copy.com will not work.
But if you still want to host your css files on this cloud storage service you can by adding ?download=1 after your link so you html should be like
<link href="http://copy.com/Kgs8EaMF71Qa7zqo/style.css?download=1" rel="stylesheet" type="text/css" />
there are several other cloud service like Dropbox,Google Drive where you can host your external CSS files.
I think, it may be due to MIME type, you uploaded assuming it will work as css file but its actual MIME type will be plain type text/plain but required MIME type to make it work as css file is text/css
So It Wont work.
This file worked perfectly for me.
here is the html code with the output.
<html>
<head>
<link href="http://copy.com/Kgs8EaMF71Qa7zqo/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
</body>
</html>

Stylesheet not working in Chrome/Safari but can work in Internet Explorer

TL;DR
I've read through many questions on Stack Overflow on this issue and I've tried to follow the given advice. Still, my CSS stylesheet will not work in Chrome/Safari but it can work in Internet Explorer.
The only odd thing that I can see about my scenario is my server is returning all files as of type application/octet-stream. I cannot change this aspect of the server. Is there something I can do to interpret my CSS file as a stylesheet in Chrome/Safari and IE?
I have an embedded web server project that I am working on. I have very limited control of the server software and the ability to make page-level settings. All I can do is create static HTML, CSS, and image files that are compiled into the server application.
As such, all files that are returned from the embedded server are declared as application/octet-stream in the HTTP header. This produces warnings in Chrome but no errors.
Initially, I had a problem loading this style sheet in Chrome/Safari but it would work in IE. After reading through a couple questions on Stack Overflow, I found that I needed to change my stylesheet declaration from:
<link rel="stylesheet" href="/styles/index.css">
to:
<link rel="stylesheet" type="text/css" href="/styles/index.css">
When I made this change Chrome & Safari still failed to process the CSS file but IE also started to ignore the stylesheet.
Oddly, if I do not declare a DOCTYPE on my HTML document I can get linked stylesheets to work in all of my browsers. This is, however, not a desirable solution.
My guess is this issue has something to do with the HTTP header declaration and that it doesn't match the type declared in the link element.
What can I do to get this stylesheet to work in Chrome, Safari, and IE while following good web development codes-of-practice (i.e. using doctypes on my HTML files and not embedding the style code in the HTML headers?)
For clarity sake, the relevant CSS/HTML code is shown below.
index.css
html {height:100%}
body {margin:0;min-height:100%;position:relative}
iframe {width:100%;height:100%;border:none}
.hdr {min-width:765px;overflow:auto}
.logo1 {float:left;margin:4px}
.logo2 {float:right;margin:4px}
.menu {position:absolute;top:70px;left:0px;bottom:0px;width:175px}
.content {position:absolute;top:70px;left:175px;bottom:0px;right:0px;}
index.htm
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" href="/styles/index.css"> <!-- Removed the type declaration so that this would at least work in IE9 //-->
</head>
<body lang="en-us">
<div class="hdr"><img class="logo1" src="/images/logo1.png" alt="Logo #1"><img class="logo2" src="/images/logo2.png" alt="Logo #2"></div>
<div class="menu"><iframe name="menu" src="/menu.shtm"></iframe></div>
<div class="content"><iframe name="main" src="/home.htm"></iframe></div>
</body>
FYI, this is a new project that is being developed from an existing one. The original project did not declare a DOCTYPE on the HTML files. Therefore, all page data was loaded and executed in the browser in quirks mode. Furthermore, the index.htm originally consisted of multiple frames within a frameset.
I am trying to update this application, using correct, and up to date methods for developing web pages. I can make this application work, but I feel that this would be at a sacrifice of future-browser compatibility if I have to rely on browser quirks mode and framesets.
I have tried to close the link tag but that doesn't help. Technically, this shouldn't be an issue since this document is declared as an HTML5 document, rather than XHTML.
It's certainly due to the application/octet-stream content type. I can re-create the issue on my end. Soon as the content type is set to text/css your HTML/CSS load fine.
As a workaround you can use <style> tags for you CSS if you can't get the server to send the correct content type.
I hate to have to answer my own question this way but the problem was most certainly with the fact that the server was returning a content type of application/octet-stream within the HTTP header.
After discussing the issue with management we had to update the code associated with the HTTP processor. This is code that is part of a third-party RTOS and we have been extremely hesitant to making any changes to this code.
However, in this case the need has out-weighed that desire. I've integrated the necessary changes to fix the HTTP header to return a content type of "text/css" for cascading style sheets. All is now right with the world.
I think I'll just chime in here. Not to answer the question, but to confirm the issue and perhaps help people with similar problems.
I had the same problem: an external css file was loaded alright, but it was not applied in Chrome. (Safari and FF were ok about it). So, same problem, slightly different cause.
It turned out that because of a bug in the webserver code the HTTP response contained two Content Types, 'text/html' and 'text/css'.
The solution was to remove the faulty 'text/html' line. It seems Chrome is pickier than other browsers about response headers. Which I suppose is legitimate, but a warning would have been nice.
btw, you can see all the http information for a loaded resource in Chrome, when you open Developer Tools, and select Network. Then click on the file that you want to investigate. (it took me a while to find that)
We had a problems with an iframe wich it's contents was updated by an external javascript routine, the CSS were loaded but were not applied. But updating the body HTML from a routine present in the iframe head worked as suposed to.
This same behaviour was not present in gecko and explorer, but happened the same at Safari browser (webkit)
Hope this could give some light in this curious case.
I would like to add one bit of information that may save some of you some time. It appeared that chrome was not recognizing my CSS either. After reading the above post I reviewed the files in the Developer Tools->Network. Turns out that Chrome was using a locally cached version of my CSS. As soon as I refreshed as opposed to accessing the URL again, it worked!
I'm no expert, but i've made this mistake before, it's rather simple.
You've written:
<link rel="stylesheet" href="/styles/index.css">
If this is a folder in the same directory as your index.html file, then you need to remove the first /. like so:
<link rel="stylesheet" href="styles/index.css">
EDIT: I think someone else mentioned this already, but it may have been overlooked.