ws4kp-linhanced/server/scripts/modules/utils/image.mjs

22 lines
626 B
JavaScript
Raw Normal View History

2022-11-22 16:19:10 -06:00
import { blob } from './fetch.mjs';
// preload an image
// the goal is to get it in the browser's cache so it is available more quickly when the browser needs it
// a list of cached icons is used to avoid hitting the cache multiple times
const cachedImages = [];
const preloadImg = (src) => {
if (!src || typeof src !== 'string') {
console.warn(`preloadImg expects a URL string, received: '${src}' (${typeof src})`);
return false;
}
2022-11-22 16:19:10 -06:00
if (cachedImages.includes(src)) return false;
blob(src);
2022-12-14 08:31:48 -06:00
cachedImages.push(src);
2022-11-22 16:19:10 -06:00
return true;
};
export {
2025-05-29 08:30:01 -05:00
// eslint-disable-next-line import/prefer-default-export
2022-11-22 16:19:10 -06:00
preloadImg,
};