我正在开发一个Angular 4应用程序,我想应用一些全局样式。继tutorial at the angular site,我创建我的应用程序的根目录下的“styles.css的”文件,我指的是样式表在我的应用程序中的index.html:CSS文件被阻止:MIME类型不匹配(X-Content-Type-Options:nosniff)
<link rel="stylesheet" type="text/css" href="styles.css">
角应用成功编译:
$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
[...]
webpack: Compiled successfully.
但是,当我访问的Chromium浏览器http://localhost:4200,控制台显示在
GET http://localhost:4200/styles.css
在Firefox浏览器中,错误的错误是一个比较明确的:
GET
http://localhost:4200/styles.css [HTTP/1.1 404 Not Found 15ms]
The resource from "http://localhost:4200/styles.css" was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).
两个文件,index.html,然后styles.css的位于我的角度应用程序的根目录。 我试图让more info about the problem:
nosniff
Blocks a request if the requested type is
"style" and the MIME type is not "text/css", or
"script" and the MIME type is not a JavaScript MIME type.
但我不明白为什么它bloking的要求,因为我引用样式表时所指定type="text/css"
。
这是什么说的'styles.css'是MIME类型? – Raven
使用浏览器开发工具查看请求和响应头。验证MIME类型是否符合您的预期。 –