📅  最后修改于: 2023-12-03 15:31:18.325000             🧑  作者: Mango
integrity
AttributeThe integrity
attribute is used to ensure that the external resource being referred to in the document hasn't been tampered with. It is used with the <script>
and <link>
elements, and its main purpose is to provide security.
The integrity
attribute is added to the <script>
and <link>
elements, and it has the following syntax:
<script src="example.js" integrity="sha384-nC34ecH9CJLzBxR5OXJSv8H3uoCsaj7H/95t+y9iqTCNW3b4yUDoLX2nj8tgEUTO" crossorigin></script>
The integrity
attribute value consists of two parts:
sha384
).When the browser loads the external resource, it calculates its hash and compares it with the hash that is specified in the integrity
attribute. If the two hashes match, the external resource is considered to be authentic, and the browser executes it. Otherwise, it is rejected.
The integrity
attribute provides several benefits:
The integrity
attribute is a valuable addition to the HTML specification that provides an additional layer of security and peace of mind for developers and users alike. By including this attribute in your <script>
and <link>
elements, you can help ensure the authenticity and integrity of your external resources.