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

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

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

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


当前回答

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

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.

其他回答

我也遇到了同样的问题,用同样的。htaccess文件来创建漂亮的url。经过几个小时的观察和实验。我发现这个错误是因为相对链接的文件。

浏览器将开始为所有css, js和图像文件获取相同的源HTML文件,当我将浏览几个步骤深入到服务器。

为了解决这个问题,你可以在HTML源代码上使用<base>标签,

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

链接到这样的文件,

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

或者对所有文件使用绝对链接。

<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" />

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

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

to

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

我也面临着同样的问题。在做了一些研究之后,我发现问题出在文件名上。实际文件的名称是“lightgaly .css”,但在链接时我输入了“lightgaly .css”。

更多信息:

它在我的本地主机上运行良好(操作系统:Windows 8.1 &服务器:Apache)。 但是当我将我的应用程序上传到远程服务器(与我的本地主机不同的操作系统和Web服务器)时,它不起作用,给了我和你一样的错误。

因此,问题是服务器的大小写敏感性(与文件名有关)。

试试这个<link rel="stylesheet" type="text/css" href="../##/yourcss.css">

哪里##是你的文件夹,其中是你的。css -文件

别忘了:..(双点)。

我在恢复一个旧的MEAN堆栈项目时遇到了同样的问题。我使用nodemon作为我的本地开发服务器,得到了相同的错误资源解释为样式表,但使用MIME类型text/html传输。我从nodemon更改为http-server,可以在这里找到。它立刻对我起了作用。