Resource interpreted as stylesheet but transferred with MIME type text/html (seems not related with web server)
Asked Answered
A

34

214

I have this problem. Chrome continues to return this error

Resource interpreted as stylesheet but transferred with MIME type text/html

The files affected by this error are just the Style, chosen and jquery-gentleselect (other CSS files that are imported in the index in the same way work well and without error). I've already checked my MIME type and text/css is already on CSS.

Honestly I'd like to start by understanding the problem (a thing that seems I cannot do alone).

Attila answered 25/3, 2014 at 10:4 Comment(7)
Can you provide the URL of this stylesheet?Retain
Just in case someone needs this. This was happening to me due to the compression of the css file. And somehow after two times of compression, one in local, one from my CDN provider, the server can not recognize it anymore.Amiamiable
This happened to me when a stylesheet tag's request was being redirected on the server because of an ordering issue of middleware (auth middleware before static file serving). The error message in the console Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3000/login". login:1 Uncaught SyntaxError: Unexpected token < showed the redirected page url instead of the original css request which made it a little hard to track down.Pargeting
I too experienced what @Pargeting ran into. It was because the stylesheet required authentication . . . on a page that was trying to perform authentication. Really hard issue to troubleshoot, but once you figure it out, it seems pretty obvious.Nobile
A lot of people has added different solutions to this issue in different environments. I had to scroll a lot before finding mine (Reactjs). Don't give up if you don't find your's near the top as is usual in SO.Cailly
Could you please add the comment you made at Mar 25 '14 (#22631658) to this actual question?Dunleavy
I was using custom .htaccess for URL beautification, so i put a new .htaccess in my assets directory with one line RewriteEngine Off and got it solved, hope it helps ;)Bowlin
M
107

i'd like to start by understanding the problem

Browsers make HTTP requests to servers. The server then makes an HTTP response.

Both requests and responses consist of a bunch of headers and a (sometimes optional) body with some content in it.

If there is a body, then one of the headers is the Content-Type which describes what the body is (is it an HTML document? An image? The contents of a form submission? etc).

When you ask for your stylesheet, your server is telling the browser that it is an HTML document (Content-Type: text/html) instead of a stylesheet (Content-Type: text/css).

I've already checked my myme.type and text/css is already on css.

Then something else about your server is making that stylesheet come with the wrong content type.

Use the Net tab of your browser's developer tools to examine the request and the response.

Melanite answered 25/3, 2014 at 10:7 Comment(3)
i think that im pretty sure that the problem is in my .htaccess wich is pastebin.com/w8UnqFs8 (i forgot to mention that this error is giving me only in subdirectory and only after a page refresh). Thanks for your explanation, was pretty helpful for understanding the problem. :)Attila
Make sure that you can access the file without logging in.Foolish
@Attila why don't you put that info in the actual question? :)Dunleavy
D
105

Using Angular?

This is a very important caveat to remember.

The base tag needs to not only be in the head but in the right location.

I had my base tag in the wrong place in the head, it should come before any tags with url requests. Basically placing it as the second tag underneath the title solved it for me.

<base href="/">

I wrote a little post on it here

Development answered 8/1, 2016 at 3:58 Comment(6)
using ng-href instead of href solved it for me !Kennie
I was getting OTS parsing error: invalid version tag instead, but found this when looking for a solution and oh my god, this saved me.Prostatectomy
In my case, I was using an .htaccess rewrite rule to change a directory to a query string variable, like such: RewriteRule ^my_dir/(.+)$ /new_dir/?my_var=$1 [L,QSA]Cornwell
Like Max, this fixed my issue despite the fact that I'm not using Angular. I placed the offending link/href first, in front of all other links, in my head section-- and the warning disappeared.Lean
might want to rename your title in your article. I don't even use Angular. Im using Swift + Leaf and this solved my problem.Phina
I think this is the case for most SPAs. This worked for my pure JS SPA (no framework).Tyrrell
V
48

I also had problem with this error, and came upon a solution. This does not explain why the error occurred, but it seems to fix it in some cases.

Include a forward slash / before the path to the css file, like so:

<link rel="stylesheet" href="/css/bootstrap.min.css">

Verret answered 27/8, 2017 at 14:15 Comment(7)
is this relevant in this case ?Lewandowski
I had lose to much time on this small mistake. If someone will read my answer and it will help him it will be relevant in this case.Verret
What actually happened is the server served the file on /css/bootstrap.min.css , but when you did not included the / it just looks it in the current directory, for example if you went to yoursite.com/hello/trilochan , it will then looks under hello/css/bootsrap.min.css , but it is really under yoursite.com/css/bootsrap.min.css, I hope I cleared this, / refers to root, and without / , it looks in current directory.Somewhat
@GillesGouaillardet It was very much relevant, I had the same problem.Somewhat
I would highly recommend to you web developer bootcamp on udemy by colt steele, it will help you clear your doubts.Somewhat
This worked for me, I have no idea why but it did. I ran into this problem on one particular page out of many using EJS. No idea why that one page had the problem and the others didn't.Nancee
What did the trick for me was adding type="text/css" to the tag.Implant
H
22

My issue was simpler than all the answers in this post.

I had to setup IIS to include static content.

enter image description here

Hanahanae answered 11/5, 2018 at 15:22 Comment(0)
J
14

Setting the Anonymous Authentication Credentials to Application Pool Identity did the trick for me.

enter image description here

Jurisconsult answered 13/12, 2016 at 13:37 Comment(0)
M
11

Try this <link rel="stylesheet" type="text/css" href="../##/yourcss.css">

where ## is your folder wherein is your .CSS - file

Don't forget about the: .. (double dots).

Mccown answered 1/12, 2016 at 23:58 Comment(3)
I added double dots and slash(../file_path). it worked for me. thanksJacy
What's the reason of adding these two ..Polycotyledon
Yikes, such a simple overlooked mistake, mine was just pointing to wrong path. Using .. just goes up 1 directory.Fryd
M
9

I was also facing the same problem. And after doing some R&D, I found that the problem was with the file name. The name of the actual file was "lightgallery.css" but while linking I has typed "lightGallery.css".

More Info:

It worked well on my localhost (OS: Windows 8.1 & Server: Apache). But when I uploaded my application to a remote server ( Different OS & Web server than than my localhost) it didn't work, giving me the same error as yours.

So, the issue was the case sensitivity (with respect to file names) of the server.

Magdalenmagdalena answered 23/9, 2015 at 8:10 Comment(0)
C
9

In case you serve static css with nginx you should add

location ~ \.css {
    add_header  Content-Type    text/css;
}
location ~ \.js {
    add_header  Content-Type    application/x-javascript;
}

or

location ~ \.css{
    default_type text/css;
}
location ~ \.js{
    default_type application/x-javascript;
}

to nginx conf

Chorion answered 19/8, 2019 at 16:8 Comment(0)
L
8

Based on the other answers it seems like this message has a lot of causes, I thought I'd just share my individual solution in case anyone has my exact problem in the future.

Our site loads the CSS files from an AWS Cloudfront distribution, which uses an S3 bucket as the origin. This particular S3 bucket was kept synced to a Linux server running Jenkins. The sync command via s3cmd sets the Content-Type for the S3 object automatically based on what the OS says (presumably based on the file extension). For some reason, in our server, all the types were being set correctly except .css files, which it gave the type text/plain. In S3, when you check the metadata in the properties of a file, you can set the type to whatever you want. Setting it to text/css allowed our site to correctly interpret the files as CSS and load correctly.

Louvain answered 5/5, 2016 at 18:53 Comment(0)
P
5

@Rob Sedgwick's answer gave me a pointer, However, in my case my app was a Spring Boot Application. So I just added exclusions in my Security Config for the paths to the concerned files...

NOTE - This solution is SpringBoot-based... What you may need to do might differ based on what programming language you are using and/or what framework you are utilizing

However the point to note is;

Essentially the problem can be caused when every request, including those for static content are being authenticated.

So let's say some paths to my static content which were causing the errors are as follows;

A path called "plugins"

http://localhost:8080/plugins/styles/css/file-1.css

http://localhost:8080/plugins/styles/css/file-2.css

http://localhost:8080/plugins/js/script-file.js

And a path called "pages"

http://localhost:8080/pages/styles/css/style-1.css

http://localhost:8080/pages/styles/css/style-2.css

http://localhost:8080/pages/js/scripts.js

Then I just add the exclusions as follows in my Spring Boot Security Config;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers(<comma separated list of other permitted paths>, "/plugins/**", "/pages/**").permitAll()
            // other antMatchers can follow here
    }

}


Excluding these paths "/plugins/**" and "/pages/**" from authentication made the errors go away.

Cheers!

Pollypollyanna answered 9/5, 2016 at 2:19 Comment(2)
@Ben Rhys-Lewis... I wonder why you think this is a Question or even looks like one for that matter. Perhaps, you want to read my answer carefully enough to see that it's actually an ANSWER - alas, one which worked in my case... and is definitely NOT a Question.Pollypollyanna
Sorry my bad. I am not sure how that happened, I made a boo-boo. Please accept my apologies.Abampere
K
4

Using Angular

In my case using ng-href instead of href solved it for me.

Note :

I am working with laravel as back-end

Kennie answered 19/7, 2016 at 8:15 Comment(2)
But where to add this ?Polycotyledon
in the link tagKennie
S
4

If you are on JSP, this problem can come from your servlet mapping. if your mapping takes url by defaut like this:

@WebServlet("/")

then the container interpret your css url, and goes to the servlet instead of going to the css file.

i had the same issue, i changed my mapping and now everyting works

Significance answered 15/4, 2018 at 20:52 Comment(0)
P
3

i was facing the same thing, with sort of the same .htaccess file for making pretty urls. after some hours of looking around and experimenting. i found out that the error was because of relatively linking files.

the browser will start fetching the same source html file for all the css, js and image files, when i would browse a few steps deep into the server.

to counter this you can either use the <base> tag on your html source,

<base href="http://localhost/assets/">

and link to files like,

<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/script.js"></script>

or use absolute links for all your files.

<link rel="stylesheet" type="text/css" href="http://localhost/assets/css/style.css" />
<script src="http://localhost/assets/js/script.js"></script>
<img src="http://localhost/assets/images/logo.png" />
Period answered 6/7, 2017 at 2:55 Comment(0)
P
2

I have a similar problem in MVC4 using forms authentication. The problem was this line in the web.config,

<modules runAllManagedModulesForAllRequests="true">

This means that every request, including those for static content, being authenticated.

Change this line to:

<modules runAllManagedModulesForAllRequests="false">
Perchance answered 12/4, 2016 at 9:28 Comment(0)
S
2

enter image description here I also face this problem recently on chrome. I just give absolute path to my CSS file problem solve.

<link rel="stylesheet" href="<?=SS_URL?>arica/style.css" type="text/css" />
Samaria answered 17/10, 2017 at 4:7 Comment(1)
You've got to be effing kidding me. Dismissed this solution like 3 times. Came on this page multiple times but after trying everything else and about to give up, I said: "heck what could go wrong". It worked!!! Mystery of lifeEmanative
C
2

For anyone that might be having this issue. I was building a custom MVC in PHP when I encountered this issue.

I was able to resolve this by setting my assets (css/js/images) files to an absolute path. Instead of using url like href="css/style.css" which use this entire current url to load it. As an example, if you are in http://example.com/user/5, it will try to load at http://example.com/user/5/css/style.css.

To fix it, you can add a / at the start of your asset's url (i.e. href="/css/style.css"). This will tell the browser to load it from the root of your url. In this example, it will try to load http://example.com/css/style.css.

Hope this comment will help you.

Cache answered 30/7, 2020 at 10:20 Comment(0)
B
1

It is because you must have set content type as text/html instead of text/css for your server page (php,node.js etc)

Byng answered 2/7, 2016 at 9:46 Comment(1)
this problem was regarding a css file, not an html oneAttila
H
1

I want to expand on Todd R's point in the OP. In asp.net pages, the web.config file defines permissions needed to access each file or folder in the application. In our case, the folder of CSS files did not allow access for unauthorized users, causing it to fail on the login page before the user was authorized. Changing the required permissions in web.config allowed unauthorized users to access the CSS files and solved this problem.

Hyacinthie answered 4/11, 2017 at 21:39 Comment(0)
A
1

I have the same exact problem and after a few minutes fooling around I deciphered that I missed to add the file extension to my header. so I changed the following line :

<link uic-remove rel="stylesheet" href="css/bahblahblah">

to

<link uic-remove rel="stylesheet" href="css/bahblahblah.css"> 
Anole answered 15/12, 2019 at 15:35 Comment(0)
F
1

Using React

I came across this error in my react profile app. My app behaved kind of like it was trying to reference a url that doesn't exist. I believe this has something to do with how webpack behaves.

If you are linking files in your public folder you must remember to use %PUBLIC_URL% before the resource like this:

<link type="text/css" rel="stylesheet" href="%PUBLIC_URL%/bootstrap.min.css" />
Flume answered 8/6, 2020 at 23:13 Comment(0)
P
0

In case anyone comes to this post and has a similar issue. I just experienced a similar problem, but the solution was quite simple.

A developer had mistakenly dropped a copy of the web.config into the CSS directory. Once deleted, all errors were resolved and the page properly displayed.

Presumptuous answered 21/10, 2015 at 21:26 Comment(3)
Thanks @Rohit Gupta for the edit. I was typing faster than my internal grammar manager would process! =)Presumptuous
This is an ASP.NET-specific solution, which is no obvious part of the question.Standoffish
@Standoffish so what? A lot of the other answers are framework-specific too, and they've helped people using those frameworks that are experiencing the same problem.Unilobed
C
0

I came across the same issue whilst resuming work on a old MEAN stack project. I was using nodemon as my local development server and got the same error Resource interpreted as stylesheet but transferred with MIME type text/html. I changed from nodemon to http-server which can be found here. It immediately worked for me.

Chasten answered 12/5, 2016 at 3:3 Comment(0)
V
0

This occurred when I removed the protocol from the css link for a css stylesheet served by a google CDN.

This gives no error:

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Architects+Daughter">

But this gives the error Resource interpreted as Stylesheet but transferred with MIME type text/html :

<link rel="stylesheet" href="fonts.googleapis.com/css?family=Architects+Daughter">
Vainglory answered 12/8, 2016 at 23:29 Comment(0)
K
0

I was facing similar issue. And Exploring solutions in this fantastic Stack Overflow page.

user54861 's response (mismatching names in case sensetivity) makes me curious to inspect my code again and realized that "I didnt upload two js files that I loaded them in head tag". :-)

When I uploaded them the issue runs away ! And code runs and page rendered without any another error!

So, moral of the story is don't forget to make sure that all of your js files are uploaded where the page is looking for them.

Kenric answered 18/7, 2017 at 16:29 Comment(2)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From ReviewVilayet
Can't be a clue to ecma script designers to add a relevant error or exception to javascript if developer didnt load resource to server? I mean "Resource interpreted as stylesheet but transferred with MIME type text/html" is confusing a bit, isn't it?Kenric
T
0

I came across the same issue with a .NET application, a CMS open-source called MojoPortal. In one of my themes and skin for a particular site, when browsing or testing it would grind and slow down like it was choking.

My issue was not of the "type" attribute for the CSS but it was "that other thing". My exact change was in the Web.Config. I changed all the values to FALSE for MinifyCSS, CacheCssOnserver, and CacheCSSinBrowser.

Once that was set the web site was speedy once again in production.

Touched answered 23/8, 2017 at 8:16 Comment(0)
Q
0

Had the same error because I forgot to send a correct header a first

header("Content-type: text/css; charset: UTF-8");
print 'body { text-align: justify; font-size: 2em; }';
Quote answered 4/7, 2018 at 17:45 Comment(0)
T
0

If nodejs and using express the below code works...

res.set('Content-Type', 'text/css');
Theron answered 12/1, 2019 at 16:7 Comment(1)
Commenting on here because it's related to Node.JS . I had to restart the app on my hosting providerCeolaceorl
A
0

I encountered this problem when loading CSS for a React layout module that I installed with npm. You have to import two .css files to get this module running, so I initially imported them like this:

@import "../../../../node_modules/react-grid-layout/css/styles.css";

but found out that the file extension has to be dropped, so this worked:

@import "../../../../node_modules/react-grid-layout/css/styles";
Athey answered 27/6, 2019 at 8:12 Comment(0)
W
0

I started to get the issue today only on chrome and not safari for the same project/url for my goormide container (node.js)

After trying several suggestions above which didn't appear to work and backtracking on some code changes I made from yesterday to today which also made no difference I ended up in the chrome settings clicking:

1.Settings;

2.scroll down to bottom, select: "Advanced";

3.scroll down to bottom, select: "Restore settings to their original defaults";

That appears to have fixed the problem as I no longer get the warning/error in the console and the page displays as it should. Reading the posts above it appears the issue can occur from any number of sources so the settings reset is a potential generic fix. Cheers

Whirlabout answered 13/2, 2020 at 0:46 Comment(0)
G
0

If you are serving the app in prod make sure you are serving the static files with service worker. I had this error when I was serving only static subfolder of React build on Django (without assets that have styles)

Grandpa answered 14/2, 2020 at 1:45 Comment(0)
I
0

I faced the same issue while configuring Postfix Admin 3.2. According to the official documentation, the whole Postfix Admin content should be extracted into a separate directory, i.e. /srv/postfixadmin and not the document root. Only the /srv/postfixadmin/public directory should be symlinked into /var/www/html document root. I have just extracted the whole content into /var/www/html. Having played with Nginx server block settings, I managed example.com/postfixadmin resolving from /var/www/html/postfixadmin/public. Nevertheless, images and CSS were not available with 404 status code. The stylesheets were broken. I got the error message OP quoted with respective 404 entries in access log.

In my case, I just moved /var/www/html/postfixadmin into /srv/postfixadmin and made ln -s /srv/postfixadmin/public /var/www/html/postfixadmin . This solved the issue completely. Here is the reference.

Iand answered 1/1, 2021 at 19:50 Comment(0)
E
-1

Using ReactJs, when I add style file to index.html using relative link such as

<link rel="stylesheet" href="./css/style.css">

and then I navigate to a route say; localhost:3000/artist and refresh, I get the error.

The error disappeared after I replaced the relative link with an absolute link say;

<link rel="stylesheet" href="http://localhost/project/public/css/style.css".

Encephalic answered 30/9, 2018 at 1:46 Comment(1)
I had this issue, same environment, and tried your solution with no luck. But you showed me a research path :-) The messages disappeared after I moved the CSS files to the public folder. Once I did there was no need for the absolute paths.Cailly
L
-1

In my case, same error was coming with JSP. This is how I got to the root of this issue: I went to the Network tab and clearly saw that the browser request to fetch the css was returning response header having "Content-type" : "text/html". I opened another tab and manually hit the request to fetch the css. It ended up returning a html log in form. Turns out that my web application had a url mapping for path = / Tomcat servlet entry : (@WebServlet({ "/, /index", }). So, any unmatching request URLs were somehow being matched to / and the corresponding servlet was returning a Log in html form. I fixed it by removing the mapping to /

Also, the tomcat configuration wrt handling css MIME-TYPE was already present.

Leia answered 17/1, 2019 at 7:32 Comment(1)
Would like to know why this answer was downvoted ? It can surely help someone to debug, if they face similar issue.Leia
D
-2

Answer might be given above. I had the same problem and couldn't resolve it. Make it sure to add external js file as

<script src="main.js"></script>
Deedeeann answered 28/6, 2018 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.