简体   繁体   English

是否应该始终使用子资源完整性和交叉引用?

[英]Should subresource integrity and cross reference always be used?

I currently have a bout 3 lots of Jquery being used from various CDN's, should I use sub resource integrity on all scripts?我目前有大约 3 批 Jquery 从各种 CDN 使用,我应该在所有脚本上使用子资源完整性吗? Should I also be using it on locally hosted Javascript files?我是否也应该在本地托管的 Javascript 文件上使用它? Here's my code:这是我的代码:

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"><\/script>')</script>
<script src="https://getbootstrap.com/docs/4.0/assets/js/vendor/popper.min.js"></script>
<script src="https://getbootstrap.com/docs/4.0/dist/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>

<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/dataTables.bootstrap4.min.js"></script>

It appears only one uses it, the others don't, would it be advisable to do it for all?似乎只有一个人使用它,其他人没有,是否建议为所有人使用它? I'm also planning on using just 3.4.1 slim.min instead of 3.2.1 and 3.4.1 separately.我还计划只使用 3.4.1 slim.min 而不是分别使用 3.2.1 和 3.4.1。 Thanks.谢谢。

For locally hosted js, it would not be suggested to use the subresource integrity if still wanted to use you can use but you need to make u generate hash every time the file changes and update the hash value to the src tag.对于本地托管的 js,如果仍然想使用可以使用,不建议使用子资源完整性,但您需要每次文件更改时生成 hash 并将 hash 值更新为 src 标签。

For the remaining, you can add but as they are the third party js and we don't know when they would be updated, if we get release notes for them we implement the SRI for those also.对于其余的,您可以添加,但由于它们是第三方 js,我们不知道它们何时会更新,如果我们获得它们的发行说明,我们也会为它们实施 SRI。

Please check the below which Help having a failover mechanism if the file updates and the hash fails https://hacks.mozilla.org/2015/09/subresource-integrity-in-firefox-43/如果文件更新并且 hash 失败https://hacks.mozilla.org/2015/09/subresource-integrity-in-firefox-43/ ,请检查下面哪个帮助具有故障转移机制

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

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