Skip to content

Instantly share code, notes, and snippets.

@WincerChan
Created May 27, 2018 07:57
Show Gist options
  • Save WincerChan/1712467b4e85713ea999c667d27cd17c to your computer and use it in GitHub Desktop.
Save WincerChan/1712467b4e85713ea999c667d27cd17c to your computer and use it in GitHub Desktop.
将跨域资源转为本地资源
// 脚本资源
let tmpWorker = await fetch(workerUrl),
workerSrcBlob = new Blob([await tmpWorker.text()], { type: 'text/javascript' }),
workerBlobURL = window.URL.createObjectURL(workerSrcBlob);
// workerBlobURL 即为网站域名下的资源
// 图片资源
let tmpImg = await fetch(imageUrl),
imgSrcBlob = new Blob([new Uint8Array(await tmpImg.arrayBuffer())]),
imgUrl = window.URL.createObjectURL(imgSrcBlob);
// imgUlr 即为网站域名下的资源
// 资源的 URL 类似: blob:https://example.com/xxxxxx-xxxx-xxxx-xxxxxxxxxxxxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment