【发布时间】:2017-11-23 06:42:16
【问题描述】:
我正在开发一个 Angular 4 应用程序,我想应用一些全局样式。在tutorial at the angular site 之后,我在我的应用程序的根目录中创建了一个“styles.css”文件,我指的是我的应用程序的 index.html 中的那个样式表:
<link rel="stylesheet" type="text/css" href="styles.css">
angular 应用编译成功:
$ 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 这两个文件都位于我的 Angular 应用程序的根目录中。 我试图得到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.
但我不明白为什么它会阻止请求,因为我在引用样式表时指定了type="text/css"。
【问题讨论】:
-
styles.css的 mimetype 是什么意思? -
使用浏览器开发工具查看请求和响应标头。验证 MIME 类型是否符合您的预期。
标签: css node.js angular express mime-types