我有这个问题。Chrome继续返回此错误
资源解释为样式表,但以MIME类型text/html传输
受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。
老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。
我有这个问题。Chrome继续返回此错误
资源解释为样式表,但以MIME类型text/html传输
受此错误影响的文件只有Style、chosen和jquery-gentleselect(以相同方式导入索引的其他CSS文件工作良好且没有错误)。我已经检查了我的MIME类型和文本/css已经在css上。
老实说,我想从理解问题开始(这似乎是我一个人做不到的事情)。
当前回答
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已经存在。
其他回答
我在MVC4中使用表单身份验证时遇到了类似的问题。问题出在web。config中的这一行,
<modules runAllManagedModulesForAllRequests="true">
这意味着每个请求,包括静态内容的请求,都要经过身份验证。
将这一行更改为:
<modules runAllManagedModulesForAllRequests="false">
使用ReactJs,当我添加样式文件到index.html使用相对链接,如
<link rel="stylesheet" href="./css/style.css"> .
然后我导航到一条路线,说;localhost:3000/artist和刷新,我得到错误。
错误消失后,我取代相对链接与绝对链接说;
<link rel=“stylesheet” href=“http://localhost/project/public/css/style.css”。
以防有人来到这个帖子,有类似的问题。我也遇到过类似的问题,但是解决方法很简单。
一名开发人员错误地丢失了一份网页副本。将config文件放到CSS目录下。删除后,所有错误都得到解决,页面正常显示。
有同样的错误,因为我忘记发送一个正确的头
header("Content-type: text/css; charset: UTF-8");
print 'body { text-align: justify; font-size: 2em; }';
如果你使用nginx提供静态css,你应该添加
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;
}
到nginx conf