JavaScript · Senior · Question 68 of 75
What does the integrity attribute on a CDN <script> protect against?
<script src="https://cdn.example/lib.js" integrity="sha384-..." crossorigin="anonymous"></script>- ✓Correct answer: Executing a file that was modified on the CDN - the browser checks its hash first
- 2Slow CDN responses
- 3Scripts being cached
Explanation
Subresource Integrity requires a fixed file version; hashes break with "latest" URLs. crossorigin is needed so the browser can read the response to verify it.