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>

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.

Further reading

Problem with a question

JavaScript · Senior · question 68

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz