javascript 如何解决错误“未在 '脚本名称' 处加载脚本,因为在给出 'X-Content-Type: nosniff' 时不允许非脚本 MIME 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47288290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 07:17:36  来源:igfitidea点击:

How to address error "Did not load script at 'script name' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given

javascriptangularjssafarimime-types

提问by Wayne F. Kaskie

I have a fairly simple Angular 1.x app that was working fine until i upgraded to Safari 11. Now, it doesn't work because almost all of the js files are blocked.

我有一个相当简单的 Angular 1.x 应用程序,它运行良好,直到我升级到 Safari 11。现在,它不起作用,因为几乎所有的 js 文件都被阻止了。

The same was true for CSS files, but removing the "rel" attribute and adding type="text/css" fixed the CSS issues.

CSS 文件也是如此,但删除“rel”属性并添加 type="text/css" 修复了 CSS 问题。

For the JS files, I've made sure to add type="text/javascript" to the script tags. I also just tried adding ./ to the beginning of the src's for giggles and they still won't load.

对于 JS 文件,我确保将 type="text/javascript" 添加到脚本标签中。我也只是尝试将 ./ 添加到 src 的开头以发出咯咯的笑声,但它们仍然无法加载。

Does anyone know how to fix this?

有谁知道如何解决这一问题?

Thanks, Wayne

谢谢,韦恩

回答by Wayne F. Kaskie

I want to just delete the question but I hope maybe this answer will still be helpful to someone.

我只想删除这个问题,但我希望这个答案仍然对某人有帮助。

So, my problem was actually that I had a bad clone of my project and it was missing files!

所以,我的问题实际上是我的项目有一个错误的克隆,并且缺少文件!

However, for anyone having the same issue:

但是,对于任何有同样问题的人:

ensuring that type="text/css" for stylesheets and type="text/javascript" did fix the issue. (for the files that actually existed)

确保样式表的 type="text/css" 和 type="text/javascript" 确实解决了问题。(对于实际存在的文件)

回答by yoAlex5

Please make sure that a response header with the name X-Content-Typeor X-Content-Type-Optionashas the text/javascriptvalue instead of nosniff.

请确保一个响应头的名称X-Content-TypeX-Content-Type-Optionas具有text/javascript价值,而不是nosniff

It is simple to make a workaround locally using Charles Proxy Rewrite tool

使用Charles Proxy Rewrite 工具在本地制定解决方法很简单

enter image description here

在此处输入图片说明