Skip to content

Do not reload images that have already been loaded (reuse the same Texture instance) #34

@levalleux-ludo

Description

@levalleux-ludo

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;
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions