13

This error shows only in chrome. I am searching this issue but not yet found any
satisfactory solution.I attached a screenshot of that error. Please suggest some idea for this. Error image

praval
  • 191
  • 1
  • 1
  • 12

5 Answers5

15

Stylesheets should have a MIME type of text/css. Your server is serving up a HTML document (probably a 404 NOT FOUND error page) when it should be serving a CSS document.

Alohci
  • 70,004
  • 12
  • 103
  • 143
  • Thanks can you give some idea how to change MIME type in MVC .net application. – praval Feb 21 '18 at 13:30
  • Hi, I tried this and found that it didn't have any effect, but changing the src attribute did, as per my answer below. Do you have any thoughts as to why this may be the case? Thanks. – Jordan Apr 20 '18 at 21:52
  • @Jordan. The two urls clearly resolve to different locations, Regardless of what the current folder is. the relative url has the "css" folder inside the "public" folder, while the absolute url doesn't. If this doesn't satisfy you, you should ask a new question. – Alohci Apr 20 '18 at 22:37
  • @Alohci yes that was just the way I typed them in - the paths are correct in the actual code. – Jordan Apr 20 '18 at 23:24
  • You should provide more explanation. The one you gave is not really helpful. – franc Mar 08 '20 at 20:29
2

Solution:
In my case, the problem was an empty @GetMapping in one of my Controllers. I deleted it and the problem was gone.

I think the same answer will help someone who's having this similar problem and context ; e.g. JSP.

Background:
I had the same problem using Spring Boot and FreeMaker.

Nimantha
  • 4,731
  • 5
  • 15
  • 38
Fox2k
  • 21
  • 2
  • [https://stackoverflow.com/help/how-to-answer](https://stackoverflow.com/help/how-to-answer) – Willie Cheng Jun 08 '20 at 03:44
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). You can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question once you have enough [reputation](https://stackoverflow.com/help/whats-reputation). - [From Review](/review/low-quality-posts/26348955) – Willie Cheng Jun 08 '20 at 03:44
  • 1
    It's really answer, I searched for this answer for 3 days, re-reading a bunch of topics with a similar error and not where this solution was not directly written. Although there were short explanations of why this could happen, it is because, in my case, the empty @GetMapping overrides servlet by default and the browser receives in the response not CSS but something else with MIME type text/html, but this is not obvious from the error. – Fox2k Jun 08 '20 at 07:38
  • 1
    @Fox2k: Restructured the answer so that it begins with the solution; in future, avoid beginning an answer with "**I have the same problem**" as it could confuse users when they are glancing through multiple answers. – Nimantha Jun 08 '20 at 09:25
0

I've found that using a path that includes the domain, rather than just a relative path to the file, fixes the issue.

I.e:

src="https://<domain>.com/public/css/style.css"

rather than:

src="../../public/css/style.css"

I don't have a reason as to why this is the case. Perhaps something to do with the way static files are being served, or because it needs to be served over https. I'm using Firebase to host / serve.

Note that this works for both css and js files, and explicitly setting the MIME type didn't have an effect for me.

Jordan
  • 451
  • 4
  • 13
0

Someone in my team had put the <link></link> tags for the css were above and outside the <head></head> tags in the masterPage.html file.

When this .html file was converted into the masterPage.master file, we got these errors. resolution was to place the <link> tags inside the <head> tags after which the converted .master file worked as intended.

Adding this here because this cause was not covered on stackOverflow, including this post - hope it could help someone in the future

Akber Iqbal
  • 12,257
  • 11
  • 34
  • 52
0

Was having the same problem using firebase hosting, the solution was to move the style sheets to the "public" folder, i am guessing this is because it wasn't being deployed.