Skip to content

Instantly share code, notes, and snippets.

@kiyop
Last active January 26, 2023 08:19
Show Gist options
  • Save kiyop/b5b1c5e14e418065537ec16219f33f4f to your computer and use it in GitHub Desktop.
Save kiyop/b5b1c5e14e418065537ec16219f33f4f to your computer and use it in GitHub Desktop.
シンプルなプリローダー
/** 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