我有这个问题。Chrome继续返回此错误

资源解释为样式表,但以MIME类型text/html传输

受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。

老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。


当前回答

如果你在prod中提供应用程序,请确保你在service worker中提供静态文件。当我在Django上只提供React构建的静态子文件夹时,我遇到了这个错误(没有具有样式的资产)

其他回答

如果nodejs和使用express 下面的代码工作…

res.set('Content-Type', 'text/css');

使用ReactJs,当我添加样式文件到index.html使用相对链接,如

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

然后我导航到一条路线,说;localhost:3000/artist和刷新,我得到错误。

错误消失后,我取代相对链接与绝对链接说;

<link rel=“stylesheet” href=“http://localhost/project/public/css/style.css”。

我在一个。net应用程序中遇到了同样的问题,一个叫做MojoPortal的CMS开源程序。在我的一个特定网站的主题和皮肤中,在浏览或测试时,它会像窒息一样磨碎和变慢。

我的问题不是CSS的“类型”属性,而是“其他东西”。我的具体变化在Web.Config中。我将MinifyCSS, CacheCssOnserver和CacheCSSinBrowser的所有值都更改为FALSE。

一旦设定好了,网站再次快速投入生产。

使用角?

这是一个需要记住的非常重要的警告。

基本标签不仅要在头部,而且要在正确的位置。

我有我的基础标签在错误的地方在头部,它应该来之前任何标签与url请求。基本上把它作为标题下面的第二个标签为我解决了这个问题。

<base href="/">

我在这里写了一篇小文章

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 /

此外,tomcat配置wrt处理css MIME-TYPE已经存在。