我正在開發一個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類型是否符合您的預期。 –