A web page includes a script tag: <script src='https://cdn.example.com/lib.js' integrity='sha384-abc123' crossorigin='anonymous'></script>. What happens if the CDN serves a modified version of lib.js?
- A.The browser fetches the file a second time with a cache-busting query string, compares the two copies, and runs whichever copy matches the hash declared in the tag
- B.The browser strips the integrity attribute after the mismatch, runs the script in a restricted sandbox without cookie access, and logs a console warning for the developer
- C.The browser rejects the response at the TLS layer, closes the connection to cdn.example.com, and retries the request over plain HTTP until the hash matches
- D.The browser computes the hash of the downloaded script and compares it to 'sha384-abc123'. If they differ, the browser refuses to execute the script and the page must handle the resource load failure
Why D is correct