Boneyard Tools

Subresource Integrity (SRI) Hash Generator

Paste the contents of a JavaScript or CSS file to generate its Subresource Integrity hash and a ready-to-paste script or link tag. The hash is computed in your browser with the Web Crypto API, so nothing is uploaded. Use it to pin third-party assets so the browser refuses to run a file that has been tampered with.

How to generate an SRI hash

  1. Paste the exact contents of the JS or CSS file you want to pin into the box.
  2. Pick a hash algorithm (sha384 is recommended) and, optionally, the asset URL and tag type.
  3. Copy the integrity value or the full script or link tag into your HTML.

Examples

SHA-384 hash of a small script

content alert('hi'), algorithm sha384
integrity="sha384-..." on <script src="app.js" crossorigin="anonymous">

SHA-256 hash of 'abc'

content abc, algorithm sha256
sha256-ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0=

Frequently asked questions

Is my file uploaded anywhere?

No. The hash is computed entirely in your browser using the Web Crypto API. The asset contents you paste never leave the page and are not sent to a server or logged anywhere.

What is Subresource Integrity and why use it?

Subresource Integrity (SRI) lets you add an integrity attribute to a script or link tag containing a cryptographic hash of the file you expect. Before running the asset, the browser hashes what it downloaded and compares it. If a CDN is compromised or the file is altered in transit, the hash will not match and the browser refuses to load it, protecting your users from injected malicious code.

Which hash algorithm should I pick?

sha384 is the common recommendation and the default here: it is strong and is what most CDNs publish. sha256 and sha512 are also valid SRI algorithms. Whichever you choose, the integrity value must be generated from the exact bytes of the file you ship, including any minification.

Why does the tag include crossorigin="anonymous"?

The integrity check only runs when the browser can read the response, which for cross-origin assets requires CORS. Adding crossorigin="anonymous" makes the browser send an anonymous CORS request so the server response can be validated. Without it, a cross-origin asset is blocked rather than checked, so the attribute is effectively required for CDN-hosted files.

Does the hash change if I edit or re-minify the file?

Yes. SRI hashes the exact byte content, so any change, even one character or a different minifier, produces a different hash. Always regenerate the integrity value whenever you update the asset, and pin a specific version rather than a moving latest URL.

Can I put more than one hash in the integrity attribute?

Yes. The integrity attribute accepts a space-separated list of hashes, and the browser accepts the resource if any one of them matches. That is useful during a rollover when you are migrating between two versions of a file.

Related tools