Image cache layer.

Allows you to cache HTMLImageElement so you can create them once Lazy loading has been handled.

Properties

cache

ProtectedReadonly cache: Map(opens in a new tab)<string, HTMLImageElement(opens in a new tab) | () => HTMLImageElement(opens in a new tab)>

Cache map

Methods

register

register(key, src, lazy?): this

Register an image in the cache.

Parameters
NameTypeDescription
keystringName of your image
srcstringSource url/path of your image
lazy?booleanShould lazy load the image (default: false)

Returns

this


get

get(key): undefined | HTMLImageElement(opens in a new tab)

Get HTMLImageElement by key

Parameters
NameTypeDescription
keystringName of your image

Returns

undefined | HTMLImageElement(opens in a new tab)


has

has(key): boolean

Check if an image exists by key

Parameters
NameTypeDescription
keystringName of your image

Returns

boolean


loaded

loaded(key): boolean

Check if an image has been loaded

Parameters
NameTypeDescription
keystringName of your image

Returns

boolean