Encrypt Online
Choose theme

Subresource Integrity for CDN assets: when a hash helps and when it breaks deploys

Use SRI deliberately for external scripts and stylesheets by understanding when fixed hashes improve trust and when mutable assets make them painful.

Encrypt Online Editorial Team3 min readProtect & Encrypt
Subresource Integrity for CDN assets: when a hash helps and when it breaks deploys guide cover

Tip

Run the workflow once with a disposable value, then do a decrypt or restore check before you share anything real.

SRI is appealing because it gives browsers a hard expectation for fetched assets. It is frustrating when teams attach it to mutable URLs and then blame the browser for doing exactly what they asked.

The real question is whether the asset URL and deployment model are stable enough to make hash pinning practical.

Summary

Definition: Subresource Integrity lets a browser verify that a fetched resource matches an expected cryptographic hash.

Why it matters: It improves trust in externally hosted assets, especially from CDNs, by detecting unexpected content changes.

Pitfall: If the asset changes without the integrity attribute being updated, the browser will block it. That is a feature, not a bug.

SRI works best with versioned immutable assets

When the asset URL includes a version or content-based filename, SRI is a strong fit. The asset is expected to remain fixed, so the integrity string can be pinned safely. When the URL is mutable and the content may drift under the same path, SRI becomes operationally noisy because every change requires a coordinated hash update.

Why “it broke my deploy” is often a success story

If a deployment fails because the browser rejects an SRI-mismatched asset, that usually means the guardrail worked. The fix is to align asset publishing and hash generation, not to decide SRI was too strict. The pain is really a release-process mismatch being surfaced honestly.

  • Use SRI on versioned or immutable assets.
  • Regenerate integrity values when asset content changes.
  • Do not pin integrity on mutable URLs and expect calm deploys.

A focused tool opportunity

An SRI hash generator fits the site’s model well because the task is narrow and practical: compute the integrity value and explain where it belongs. That is immediately useful to small sites and documentation-minded developers.

Quick example

Use this when you want a sanity check for whether SRI will be stable in your deployment pipeline.

What to notice: SRI and mutable URLs can coexist, but only if the release process updates both together.

Text
Immutable versioned asset URL -> SRI is usually a good fit
Mutable asset at the same URL -> expect integrity churn

Practical check

  • Pin SRI to versioned assets whenever possible.
  • Treat integrity mismatch as a release-process signal, not as random browser behavior.
  • Regenerate and republish hashes as part of the same asset update step.

FAQ

Does SRI work for local first-party assets too?

It can, but it is most often discussed for externally hosted subresources where trust boundaries are wider.

Can I use SRI without caring about versioning?

You can, but mutable assets will make it much harder to maintain.

Developer workflow

Use this guide as a local handling check before a secret or protected file leaves your machine.

  1. Start with a harmless value that has the same shape as the real secret.
  2. Run the matching browser tool and copy the result into a scratch note.
  3. Run the decrypt, restore, or verification step before you share the real output.
Text
1. disposable input
2. browser-only protect/encrypt step
3. decrypt or restore check
4. share only the intended artifact

References