Javascript 拒绝从...应用样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48904452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refused to apply style from... because its MIME type ('text/html') is not a supported style-sheet MIME type, and strict MIME checking is enabled
提问by praval
This error shows only in chrome. I am searching this issue but not yet found any
satisfactory solution.I attached a screenshot of that error. Please suggest some idea for this. Error image
此错误仅在 chrome 中显示。我正在搜索此问题,但尚未找到任何
令人满意的解决方案。我附上了该错误的屏幕截图。请为此提出一些想法。错误图片
采纳答案by Alohci
Stylesheets should have a MIME type of text/css. Your server is serving up a HTML document (probably a 404 NOT FOUND error page) when it should be serving a CSS document.
样式表的 MIME 类型应为text/css. 您的服务器在应该提供 CSS 文档时提供了一个 HTML 文档(可能是一个 404 NOT FOUND 错误页面)。
回答by Jordan
I've found that using a path that includes the domain, rather than just a relative path to the file, fixes the issue.
我发现使用包含域的路径,而不仅仅是文件的相对路径,可以解决问题。
I.e:
IE:
src="https://<domain>.com/public/css/style.css"
src="https://<domain>.com/public/css/style.css"
rather than:
而不是:
src="../../public/css/style.css"
src="../../public/css/style.css"
I don't have a reason as to why this is the case. Perhaps something to do with the way static files are being served, or because it needs to be served over https. I'm using Firebase to host / serve.
我没有理由说明为什么会这样。也许与静态文件的提供方式有关,或者因为它需要通过https. 我正在使用 Firebase 来托管/服务。
Note that this works for both cssand jsfiles, and explicitly setting the MIME type didn't have an effect for me.
请注意,这对css和js文件都有效,并且显式设置 MIME 类型对我没有影响。
回答by Akber Iqbal
Someone in my team had put the <link></link>tags for the css were above and outside the <head></head>tags in the masterPage.htmlfile.
我团队中的某个人将<link></link>css 的<head></head>标签放在masterPage.html文件中标签的上方和外部。
When this .html file was converted into the masterPage.masterfile, we got these errors. resolution was to place the <link>tags inside the <head>tags after which the converted .masterfile worked as intended.
当这个 .html 文件被转换成masterPage.master文件时,我们得到了这些错误。解决方案是将<link>标签放置在标签内<head>,然后转换后的.master文件按预期工作。
Adding this here because this cause was not covered on stackOverflow, including this post- hope it could help someone in the future
在此处添加此内容是因为 stackOverflow 中未涵盖此原因,包括此帖子-希望它可以在将来对某人有所帮助
回答by Giovanna PC
Was having the same problem using firebase hosting, the solution was to move the style sheets to the "public" folder, i am guessing this is because it wasn't being deployed.
使用 firebase 托管时遇到了同样的问题,解决方案是将样式表移动到“公共”文件夹,我猜这是因为它没有被部署。

