Created
May 27, 2018 07:57
-
-
Save WincerChan/1712467b4e85713ea999c667d27cd17c to your computer and use it in GitHub Desktop.
将跨域资源转为本地资源
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 脚本资源 | |
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