我有这个问题。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已经存在。
其他回答
我在一个。net应用程序中遇到了同样的问题,一个叫做MojoPortal的CMS开源程序。在我的一个特定网站的主题和皮肤中,在浏览或测试时,它会像窒息一样磨碎和变慢。
我的问题不是CSS的“类型”属性,而是“其他东西”。我的具体变化在Web.Config中。我将MinifyCSS, CacheCssOnserver和CacheCSSinBrowser的所有值都更改为FALSE。
一旦设定好了,网站再次快速投入生产。
我也遇到过类似的问题。在这个奇妙的Stack Overflow页面中探索解决方案。
user54861的响应(大小写不匹配的名字)让我很好奇,再次检查我的代码,并意识到“我没有上传两个js文件,我在头标签中加载了它们”。: -)
当我上传他们的问题跑了!并且代码运行和页面呈现没有任何其他错误!
所以,这个故事的寓意是,不要忘记确保你所有的js文件都上传到了页面需要它们的地方。
I faced the same issue while configuring Postfix Admin 3.2. According to the official documentation, the whole Postfix Admin content should be extracted into a separate directory, i.e. /srv/postfixadmin and not the document root. Only the /srv/postfixadmin/public directory should be symlinked into /var/www/html document root. I have just extracted the whole content into /var/www/html. Having played with Nginx server block settings, I managed example.com/postfixadmin resolving from /var/www/html/postfixadmin/public. Nevertheless, images and CSS were not available with 404 status code. The stylesheets were broken. I got the error message OP quoted with respective 404 entries in access log.
在我的情况下,我只是移动/var/www/html/postfixadmin到/srv/postfixadmin和ln -s /srv/postfixadmin/公共/var/www/html/postfixadmin。这完全解决了问题。 这是参考资料。
我在为一个用npm安装的React布局模块加载CSS时遇到了这个问题。你必须导入两个.css文件来让这个模块运行,所以我最初导入它们是这样的:
@import "../../../../node_modules/react-grid-layout/css/styles.css";
但发现文件扩展名必须被删除,所以这是有效的:
@import "../../../../node_modules/react-grid-layout/css/styles";
我想从理解问题开始
浏览器向服务器发出HTTP请求。然后服务器做出一个HTTP响应。
请求和响应都由一堆头部和一个(有时是可选的)包含一些内容的主体组成。
如果有一个主体,那么其中一个头是Content-Type,它描述了主体是什么(它是HTML文档吗?一个图像?表单提交的内容?等等)。
当您请求样式表时,服务器会告诉浏览器这是一个HTML文档(Content-Type: text/ HTML),而不是一个样式表(Content-Type: text/css)。
我已经查过了。Type and text/css已经在css上了。
那么,您的服务器的其他部分使样式表具有错误的内容类型。
使用浏览器开发人员工具的Net选项卡检查请求和响应。