Skip to content

Instantly share code, notes, and snippets.

@saintplay
Last active November 3, 2023 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saintplay/4cc46f98d52534941c807572019ad239 to your computer and use it in GitHub Desktop.
Save saintplay/4cc46f98d52534941c807572019ad239 to your computer and use it in GitHub Desktop.
Get SHA-256 from asset
fetch('/assets/app.bundle.js')
.then(response => { if (response.status > 200) throw new Error('not found'); return response.arrayBuffer() })
.then(async (buffer) => {
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
})
.then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment