Skip to content

subresourceIntegrity(options?)

Computes Subresource Integrity for final local JS/CSS and updates HTML script, stylesheet, preload, and modulepreload tags.

ts
subresourceIntegrity({
	algorithms: ["sha384", "sha512"],
	crossorigin: "anonymous",
	manifest: "meta/integrity.json",
	strict: false,
});
OptionDefaultDescription
algorithms"sha384"sha256 / sha384 / sha512; multiple digests supported
filterJavaScript and CSSRegExp or (fileName, type) => boolean
crossorigin"anonymous"anonymous / use-credentials; false disables automatic addition
overwritetrueOverwrite existing local integrity/crossorigin attributes
manifestfalsetrue emits integrity-manifest.json; a string specifies a safe relative path
strictfalseFail the build when local scripts/styles cannot be matched to bundle output

Full URLs count as local only when same-origin with an absolute base and under its path. Other remote assets are not downloaded or hashed. publicDir files are outside the bundle; include them in the graph or handle separately before enabling strict mode. Place before precompression even when used alone.

subresourceIntegrity Integrity

Generates SRI for final Vite JS/CSS and updates built HTML entries.

Runs late in output processing. Place before precompression so .gz/.br HTML matches the integrity-injected originals.

Signature

ts
export function subresourceIntegrity(options: SubresourceIntegrityPluginOptions = {}): Plugin;

Example

ts
import { subresourceIntegrity } from "fast-vite-plugins";

const plugin = subresourceIntegrity({ algorithms: ["sha384"], manifest: "meta/integrity.json" });

export default { plugins: [plugin] };

Input

InputTypeRequired / defaultDescription
optionsSubresourceIntegrityPluginOptionsOptional; defaults to {}Digest algorithms, asset filters, CORS, overwrite, manifest, and strict settings.

Returns

ValueTypeDescription
pluginPluginSubresource Integrity plugin for Vite plugins.