Last active
January 26, 2023 08:19
-
-
Save kiyop/b5b1c5e14e418065537ec16219f33f4f 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
/** Single preloader */ | |
export const preload = | |
(url: string): Promise<string> => | |
fetch(url).then(res => res.blob()).then(blob => URL.createObjectURL(blob)) | |
/** Multiple preloader */ | |
export const preloadAll = | |
(urls: { [key: string]: string }): Promise<{ [key: string]: string }> => | |
Promise.all(Object.entries(urls).map(async ([k, v]) => [k, await preload(v)])).then(Object.fromEntries) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment