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

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

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

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


当前回答

我有同样的问题,几分钟后,我破译,我错过了添加文件扩展名到我的头。所以我改了下面这行:

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

to

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

其他回答

我想从理解问题开始

浏览器向服务器发出HTTP请求。然后服务器做出一个HTTP响应。

请求和响应都由一堆头部和一个(有时是可选的)包含一些内容的主体组成。

如果有一个主体,那么其中一个头是Content-Type,它描述了主体是什么(它是HTML文档吗?一个图像?表单提交的内容?等等)。

当您请求样式表时,服务器会告诉浏览器这是一个HTML文档(Content-Type: text/ HTML),而不是一个样式表(Content-Type: text/css)。

我已经查过了。Type and text/css已经在css上了。

那么,您的服务器的其他部分使样式表具有错误的内容类型。

使用浏览器开发人员工具的Net选项卡检查请求和响应。

有同样的错误,因为我忘记发送一个正确的头

header("Content-type: text/css; charset: UTF-8");
print 'body { text-align: justify; font-size: 2em; }';

使用角

在我的情况下,使用ng-href而不是href解决了这个问题。

注意:

我和laravel一起做后台

我在MVC4中使用表单身份验证时遇到了类似的问题。问题出在web。config中的这一行,

<modules runAllManagedModulesForAllRequests="true">

这意味着每个请求,包括静态内容的请求,都要经过身份验证。

将这一行更改为:

<modules runAllManagedModulesForAllRequests="false">

根据其他的回答,这条消息似乎有很多原因,我想我只是分享我的个人解决方案,以防将来有人有我的确切问题。

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.