討論串來源: https://www.facebook.com/tomchentw/posts/1537332202978535
原始推文: Jason Miller 🦊⚛ on Twitter: "The web is getting async image decoding!"
| var image = new Image(); | |
| image.src = filename; | |
| image.onload = function() { | |
| // use image | |
| } | |
| fetch(filename).then(res => { | |
| res.blob().then(blob => { | |
| createImageBitmap(blob).then( image => { | |
| // use image | |
| } | |
| } | |
| }); |
| fetch(filename) | |
| .then(res => res.blob()) | |
| .then(blob => createImageBitmap(blob)) | |
| .then(image => image.whatever()); |
| (async function aa() { | |
| var res = await fetch(filename); | |
| var blob = await res.blob(); | |
| var image = await createImageBitmap(blob); | |
| console.log(image); | |
| })(); |
| (async function aa() { | |
| console.log(await createImageBitmap(await (await fetch(filename)).blob())) | |
| })() |
thx for recording.