In function noOfflineSupport
, which is the default branch, instead of directly setting img.src
, it requested the url and converted to blob, and converted to blob url, and loaded into img.src
.
This could lead to at most 3x memory usage before gc kick in, the memory usage could include the requested response, the blob, and img.src, making it against memory optimizations espacially on low-end devices, like a mobile phone.
So here are the questions:
- Why doing this?
- Could there be a method or option to disable this?
- If this is for doing retry, could it just retry using error event?
loadImageWithRetry by gpt
function loadImageWithRetry(src, maxRetries, delay) {
let retries = 0;
function load() {
const img = new Image();
img.onload = function () {
// Image loaded successfully.
console.log('Image loaded successfully');
};
img.onerror = function () {
// Image failed to load.
retries++;
if (retries < maxRetries) {
// Retry loading the image after a delay.
console.log(`Retry ${retries} of ${maxRetries}`);
setTimeout(load, delay);
} else {
console.error(`Failed to load image after ${maxRetries} retries`);
}
};
img.src = src;
}
// Start loading the image.
load();
}
// Usage
const imageUrl = 'https://example.com/your-image.jpg';
const maxRetries = 3; // Maximum number of retry attempts
const retryDelay = 1000; // Delay in milliseconds between retries
loadImageWithRetry(imageUrl, maxRetries, retryDelay);