錯誤提示:Refused to execute script from 'xxxx' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
情況:引入上傳在github的CSS、JS文件,無法顯示樣式,開發者模式(F12)顯示Refused to execute script from 'xxx' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled。能訪問到CSS、JS文件(在網頁下查看源代碼,訪問CSS、JS文件),沒有出現404問題。
出現404問題請看:引入放在github上的CSS、JS樣式文件樣式不顯示——訪問404問題
https://blog.csdn.net/qq_38243612/article/details/104334203
這是請求頭引起的,一般請求頭是Content-Type: text/html;charset:utf-8(HTML格式);
常見的媒體格式還有:
text/plain :純文本格式
text/xml : XML格式
image/gif :gif圖片格式
image/jpeg :jpg圖片格式
image/png:png圖片格式
這個X-Content-Type-Options是nosniff,錯誤解釋:當你請求一個文件從raw.githubusercontent.com
,gist.githubusercontent.com
,bitbucket.org
或者gitlab.com
,他們通常提供(在JavaScript,HTML,CSS,以及一些其他文件類型的情況下)用Content-Type
的text/plain
。結果,大多數現代瀏覽器實際上不會將其解釋爲JavaScript,HTML或CSS。
可以利用https://raw.githack.com/解決,用法簡單,只需將你的github鏈接填入下圖紅色位置,即可看到use url裏面有生成其他鏈接,引入那個鏈接,將不再報錯,CSS、JS樣式顯示出來。