As loading of images takes some relevant time, it's possible to cache the textures for images that have already been loaded and reuse them if user is reopening the same product details (or is just looping over the image list of the product).
An exemple of such an implementation can be found in boson-dcl v1: https://github.com/bosonprotocol/boson-dcl/blob/main/src/ImageServer.ts
export class ImageServer {
imageMap: { [key: string]: Image } = {};
constructor() {}
getImage(imageUrl : IImageDefinition): Image {
const imageUrl = imageDefinition.imageUrl;
if (this.imageMap[imageUrl]) {
return this.imageMap[imageUrl];
}
const image = new Image({
texture: new Texture(imageUrl),
width: imageDefinition.width,
height: imageDefinition.height,
});
this.imageMap[imageUrl] = image;
return image;
}
}
As loading of images takes some relevant time, it's possible to cache the textures for images that have already been loaded and reuse them if user is reopening the same product details (or is just looping over the image list of the product).
An exemple of such an implementation can be found in boson-dcl v1: https://github.com/bosonprotocol/boson-dcl/blob/main/src/ImageServer.ts