A simple batch assets loader. This is a fork from Ian McGregor's assets-loader.
npm install watsondg/assets-loader --S
var AssetsLoader = require('assets-loader');
// load some assets:
var loader = new AssetsLoader({
assets: [
// image
'/images/picture.png',
// image with crossorigin
{ url: '/images/picture.jpg', crossOrigin: 'anonymous' },
// image as blob
{ url: '/images/picture.webp', blob: true },
// specify id for retrieval
{ id: 'picture', url: '/images/picture.jpg' },
// json
'data.json',
{ url: 'data.json' },
{ url: '/endpoint', type: 'json' },
// jsonp
{ url: '/endpoint', type: 'jsonp' },
{ url: 'data.json', type: 'jsonp', callback: 'dataCallback', timeout: 5000 },
// video
'video.webm',
{ url: 'video.mp4', blob: true },
// audio
'audio.ogg',
{ url: 'audio.ogg', blob: true },
{ url: 'audio.mp3', webAudioContext: audioContext },
]
})
.on('complete', function(assets) {
console.log(loader.get('picture'));
})
.start();
More usage and examples on the original project's page.
See all supported formats here.
Create a new instance of VideoCache.
options
- (OPTIONAL) - configuration parameters. Can be an URL or an object containing the following properties:
- assets: an array of files to load. It can be a string (url) or an object containing an
url
property as well as anid
for easier retrieval, as well as any of the following parameters. - basePath: the base URL to prepend to the file URL.
- blob: force loading by Blob if supported.
- crossOrigin: for image loading.
- webAudioContext: a pre-existing audio context to use.
Add a subloader.
options
- (OPTIONAL) - configuration parameters, same as constructor.
Start loading the assets.
Return the loaded file.
id
- id if specified or path to the file requested.
Return a subloader.
id
- id of the subloader.
Stop loading and dispose the instance.
MIT.