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

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

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

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


当前回答

使用的反应

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

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

<link type="text/css" rel="stylesheet" href="%PUBLIC_URL%/bootstrap.min.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已经存在。

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

更多信息:

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

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

@Rob Sedgwick的回答给了我一个指针,然而,在我的情况下,我的应用程序是一个春季启动应用程序。所以我只是在我的安全配置中为相关文件的路径添加了排除…

说明—此解决方案基于springboot…你需要做的可能会根据你使用的编程语言和/或你使用的框架而有所不同

然而,要注意的一点是;

从本质上讲,当每个请求,包括 那些静态内容正在被验证。

所以让我们说一些路径到我的静态内容,导致错误如下;

一个叫做“插件”的路径

http://localhost:8080/plugins/styles/css/file-1.css http://localhost:8080/plugins/styles/css/file-2.css http://localhost:8080/plugins/js/script-file.js

还有一个路径叫做pages

http://localhost:8080/pages/styles/css/style-1.css http://localhost:8080/pages/styles/css/style-2.css http://localhost:8080/pages/js/scripts.js

然后,我只需在Spring Boot安全配置中添加如下排除项;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers(<comma separated list of other permitted paths>, "/plugins/**", "/pages/**").permitAll()
            // other antMatchers can follow here
    }

}

从身份验证中排除这些路径“/plugins/**”和“/pages/**”可以消除错误。


干杯!

我也遇到了同样的问题,用同样的。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" />

我最近在chrome浏览器上也遇到了这个问题。我只是给我的CSS文件解决问题的绝对路径。

<link rel="stylesheet" href="<?=SS_URL?>arica/style.css" type="text/css" />