Methods
preload(images) → {Basic.Deferred.<(Image|Array.<Image>)>|Image}
Preloads images by URL, so that subsequent usages are served from browser cache. Images can be preloaded anonymously or with a given name. So you can either just use the url again, or, to be super-sure, call the method again, with just the image name to get the preloaded image itself.
The function returns a Deferred, which resolves, after the images have loaded, with either an array of preloaded images or a single image, if only one has been defined. The Deferred contains all images newly created for preloading on the provision property before the Deferred resolves.
Parameters:
Name | Type | Description |
---|---|---|
images |
String | Array.<String> | Object.<String, String> | a URL, an array of URLs or a plain object containing named URLs. In case the string is an already used name, the image object from the named preloaded images cache is returned. |
Returns:
either a Deferred, resolving after images are preloaded, or a requested cached image
- Type
- Basic.Deferred.<(Image|Array.<Image>)> | Image
Example
preload([url1, url2, url3]).then(images => { alert(`loaded ${images.length} images`); });
const provisionalImage preload({name1 : url1, name2 : url2}}).provision.name1;
const preloadedImage = preload('name1');