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

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

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

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


当前回答

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

<modules runAllManagedModulesForAllRequests="true">

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

将这一行更改为:

<modules runAllManagedModulesForAllRequests="false">

其他回答

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

更多信息:

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

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

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

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.

使用的反应

我在我的react profile应用程序中遇到了这个错误。我的应用程序表现得有点像它试图引用一个不存在的url。我相信这与webpack的行为有关。

如果你在公用文件夹中链接文件,你必须记住在资源之前使用%PUBLIC_URL%,就像这样:

<link type="text/css" rel="stylesheet" href="%PUBLIC_URL%/bootstrap.min.css" />

对于任何可能有这种问题的人。 当我遇到这个问题时,我正在用PHP构建一个自定义MVC。

我能够通过将我的资产(css/js/images)文件设置为绝对路径来解决这个问题。 而不是使用url像href="css/style.css"使用整个当前url来加载它。例如,如果您在http://example.com/user/5,它将尝试在http://example.com/user/5/css/style.css加载。

为了解决这个问题,你可以在资产url的开头添加一个/(即href="/css/style.css")。这将告诉浏览器从url的根目录加载它。在本例中,它将尝试加载http://example.com/css/style.css。

希望这篇评论对你有所帮助。

答案可以在上面给出。我也遇到过同样的问题,但无法解决。确保添加外部js文件为

<script src="main.js"></script>