A library for loading common web assets
npm install preloader
A library for loading common web assets

The preloader is capable of loading almost all types of files, if it does not understand a file type, it will attempt to load it as a basic xhr request. It extends the nodejs event emitter and uses the following events.
``progress`: Event Sends updates on loading progress to other part of application (loading ui)`complete`: Event Notifies loading completion to other part of application
Here is a common usage of the preloader.
`js`
var preloader = require('preloader');
var loader = preloader({
xhrImages: false
});
loader.on('progress',function(progress) {
console.log(progress);
});
loader.on('complete',function() {
var data = loader.get('site_data.json');
console.log('all content loaded!');
});
loader.add('video1.mp4');
loader.add('test_image.jpg',{
onComplete: function(content) {
document.body.appendChild(loader.get('test_image.jpg'));
}
});
loader.add('site_data.json');
loader.load();
This creates a new instance of the preloader on which on you use the following api. It is not a singleton and must be instantiated to use. The options object contains the following properties.
`xhrImages` Loads images via XHR and converts to a Blob instead of the image tag, default: false`onComplete` A function to attach to the complete event`onProgress` A function to attach to the progress event`throttle` A integer specifying maximum amount of connections at a time, 0 = infinite
Generic asset loader function - determines loader to be used based on file-extension
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load image - uses the LoaderImage loader
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load JSON - uses the LoaderJSON loader
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load text - uses the LoaderText loader
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load video - uses the LoaderVideo loader
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load audio - uses the LoaderAudio loader
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load image - uses the LoaderImage loader
`url`: String URL of asset`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Load asset using custom loader
`url`: String URL of asset`loaderType`: function Custom loader function`options`: Object Custom options to override the global options created at instantiation, can also pass in onComplete and onProgress to listen to the events on this particular item.
Sets percentage of total load for a given asset
`url`: String URL of asset`percentageOfLoad`: Number representing percentage of total load
Begins loading process
Stops loading process
Retrieves loaded asset from loader
`url`: String URL of asset`Returns`: asset instance
Resets loading so you can reuse the preloader. does not remove cached loads so get()` continues to function for all assets.
MIT, see LICENSE.md for details.