简体   繁体   English

拒绝从...应用样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查

[英]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

This error shows only in chrome.此错误仅在 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错误图片

Stylesheets should have a MIME type of text/css .样式表应该有一个 MIME 类型的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.您的服务器在应该提供 CSS 文档时提供了一个 HTML 文档(可能是一个 404 NOT FOUND 错误页面)。

Solution :解决方案
In my case, the problem was an empty @GetMapping in one of my Controllers.就我而言,问题是我的一个控制器中有一个空的@GetMapping I deleted it and the problem was gone.我删除了它,问题就消失了。

I think the same answer will help someone who's having this similar problem and context ;我认为相同的答案会帮助遇到类似问题和背景的人; eg JSP.例如JSP。

Background :背景
I had the same problem using Spring Boot and FreeMaker.我在使用 Spring Boot 和 FreeMaker 时遇到了同样的问题。

I've found that using a path that includes the domain, rather than just a relative path to the file, fixes the issue.我发现使用包含域的路径,而不仅仅是文件的相对路径,可以解决问题。

Ie:即:

src="https://<domain>.com/public/css/style.css"

rather than:而不是:

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 .也许与静态文件的提供方式有关,或者因为它需要通过https I'm using Firebase to host / serve.我正在使用 Firebase 来托管/服务。

Note that this works for both css and js files, and explicitly setting the MIME type didn't have an effect for me.请注意,这适用于cssjs文件,并且显式设置 MIME 类型对我没有影响。

Someone in my team had put the <link></link> tags for the css were above and outside the <head></head> tags in the masterPage.html file.我团队中的某个人将 CSS 的<link></link> <head></head>标签放在masterPage.html文件中<head></head>标签的上方和外面。

When this .html file was converted into the masterPage.master file, we got these errors.当这个 .html 文件被转换成masterPage.master文件时,我们得到了这些错误。 resolution was to place the <link> tags inside the <head> tags after which the converted .master file worked as intended.解决方案是将<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 中未涵盖此原因,包括此帖子-希望它可以在将来对某人有所帮助

使用 firebase 托管时遇到了同样的问题,解决方案是将样式表移动到“公共”文件夹,我猜这是因为它没有被部署。

Suggesting to move the css files into the main folder sorted the problem.建议将 css 文件移动到主文件夹中解决了问题。 Thanks a lot for the help :)非常感谢您的帮助 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拒绝应用“ <URL> &#39;,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型,并且启用了严格的MIME检查 - Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled 拒绝应用{filename}中的样式,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型 - Refused to apply style from {filename} because its MIME type ('text/html') is not a supported stylesheet MIME type Django:拒绝从...应用样式,因为它的 MIME 类型(&#39;text/html&#39;)不是受支持的样式表 MIME 类型 - Django: Refused to apply style from ... because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用来自“xxx/style.css”的样式,因为它的 MIME 类型(“text/html”)不是受支持的样式表 MIME 类型 - Refused to apply style from 'xxx/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝从 &#39;URL&#39; 执行脚本,因为它的 MIME 类型 (&#39;text/html&#39;) 不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script from 'URL' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled 拒绝从“ file_name.php”执行脚本,因为其MIME类型(“ text / html”)不可执行,并且启用了严格的MIME类型检查 - Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled 拒绝应用样式,因为它的 MIME 类型('text/html')不是受支持的样式表类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet type 应用 css 样式时出现角度错误:拒绝从“路径”应用样式,因为其 MIME 类型(“文本/html”)不是受支持的样式表 MIME 类型 - Angular error when applying css style: Refused to apply style from 'path' because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用来自 'http://localhost:3000/css/style.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型 - Refused to apply style from 'http://localhost:3000/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM