diff --git a/app/composables/useImages.ts b/app/composables/useImages.ts index f69c4bf..9d47e67 100644 --- a/app/composables/useImages.ts +++ b/app/composables/useImages.ts @@ -1,15 +1,16 @@ +const imageCache = new Map(); + export const useImages = (...paths: string[]) => { const images = paths.map((path) => { + if (imageCache.has(path)) { + return imageCache.get(path)!; + } + const img = document.createElement("img"); img.src = path; - return img; - }); + imageCache.set(path, img); - onBeforeUnmount(() => { - images.forEach((img) => { - img.src = ""; - img.remove(); - }); + return img; }); return images;