简体   繁体   English

通过脚本在 HTML 加载 Lodash 返回错误

[英]Loading Lodash in HTML via Script Returns Error

I'm pretty new to html, javascript and stuff, so I hope you can help me.我对 html、javascript 之类的东西很陌生,所以希望你能帮助我。

I would like to use Lodash, and I therefore do the following in my HTML-file:我想使用 Lodash,因此在我的 HTML 文件中执行以下操作:

<script src="https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/lodash.js"></script>

In Firefox (version 78.0.2 (64-bit)) under Ubuntu 20.04, this results in the following error in the Firefox-console:在 Ubuntu 20.04 下的 Firefox(版本 78.0.2(64 位))中,这会导致 Firefox-console 出现以下错误:

The resource from “https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/lodash.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).来自“https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/lodash.js”的资源由于 MIME 类型(“text/plain”)不匹配(X-Content-Type-Options : 无嗅)。

Any ideas on how to fix this?有想法该怎么解决这个吗?

The problem is that, GitHub pages are not made to be used for this purpose.问题是,GitHub 页面并非用于此目的。 If you analyze the request response, you can see that the response is of type "text/plain" but it should be "application/javascript".如果分析请求响应,您可以看到响应的类型为“text/plain”,但它应该是“application/javascript”。 So you have a few possible solutions.所以你有几个可能的解决方案。 Either host the script file yourself on your web server or use a CDN (Content Delivery Network) service.您可以自己在 web 服务器上托管脚本文件,也可以使用 CDN(内容分发网络)服务。 If you want to use the latter, do the following.如果要使用后者,请执行以下操作。

Replace:代替:

https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/lodash.js    

to:到:

https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM