preload gifs

This commit is contained in:
Matt Walsh
2020-09-23 11:49:15 -05:00
parent 36673b1f1d
commit 77c0744cb3
12 changed files with 39 additions and 14 deletions

View File

@@ -16,7 +16,7 @@ const utils = (() => {
} catch (e) {
console.error('Unable to get point');
console.error(lat,lon);
console.error(e);
console.error(e.status, e.responseJSON);
return false;
}
};
@@ -45,6 +45,19 @@ const utils = (() => {
});
};
// 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 preload = (src) => {
if (cachedImages.includes(src)) return false;
const img = new Image();
img.scr = src;
cachedImages.push(src);
console.log(cachedImages);
return true;
};
// *********************************** unit conversions ***********************
Math.round2 = (value, decimals) => Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
@@ -360,6 +373,7 @@ const utils = (() => {
image: {
load: loadImg,
superGifAsync,
preload,
},
weather: {
getPoint,