So,I am learning javascript.And from my understanding script can have an attribute called integrity who value is a hash value.
<script> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" </script>
From my understanding,the integrity attribute is used to check if the external source file is not corrupted or has been changed.
from where will I get the hashvalue that can used as the value of integrity attribute.
2
Answers
You may generate the cryptographic hash here:
https://www.srihash.org/
Further Reading:
Here’s how you can get the integrity hash for a script tag:
Replace filename.js with the name of your JavaScript file. This command will generate a Base64-encoded cryptographic hash of your file using the SHA-384 algorithm2.
After generating the hash, you can add it to your script tag like this:
Replace filename.js with the path to your JavaScript file and generatedhash with the hash you generated1.
Note that the crossorigin attribute should also be included when using the integrity attribute1. This attribute tells the browser to request the script with CORS enabled, which is necessary because the integrity check fails without CORS1.
Also, side note: Here’s another post where this was answered How to get the integrity value for a jquery version for script