由于 MIME 类型不匹配而阻止的资源(X-内容-类型-选项:nosniff)

2022-08-30 04:34:01

我正在使用JavaScript和HTML开发一个网页,当我从我的HTML页面收到这个错误列表时,一切都很顺利:

The resource from “https://raw.githubusercontent.com/dataarts/dat.gui/master/build/dat.gui.min.js”
  was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).
The resource from “https://raw.githubusercontent.com/mrdoob/three.js/dev/build/three.js” was
  blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).
The resource from “https://raw.githubusercontent.com/mrdoob/three.js/master/examples/js/renderers/CanvasRenderer.js”
  was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).
The resource from “https://raw.githubusercontent.com/mrdoob/three.js/master/examples/js/renderers/Projector.js”
  was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).
The resource from “https://raw.githubusercontent.com/mrdoob/three.js/dev/build/three.js” was
  blocked due to MIME type mismatch (X-Content-Type-Options: nosniff).

这些错误出现在浏览器自动更新(Mozilla Firefox)之后,可能是在设置中发生了一些变化。你知道解决这个问题的方法吗?


答案 1

检查文件路径是否正确并且文件是否存在 - 在我的情况下,这就是问题所在 - 当我修复它时,错误消失了


答案 2

可以通过将URL更改为使用镜像/代理来解决此问题。而不是使用 GitHub:

https://raw.githubusercontent.com/svnpenn/bm/master/yt-dl/yt-dl.js
Content-Type: text/plain; charset=utf-8

使用第三方缓存:

https://cdn.rawgit.com/svnpenn/bm/master/yt-dl/yt-dl.js
content-type: application/javascript;charset=utf-8

rawgit.com GitHub的缓存代理服务,自2018年以来一直关闭。查看其常见问题解答