Install it per NPM and call its quicklink(); method – for example after the DOM has loaded – to initialize the script.
Amongst ignore patterns, it’s also possible to define the origins which are allowed to be preloaded.
As used in Cut The Rope. Resulting code when used looks like:
// Create the loader and queue our 3 images. Images will not
// begin downloading until we tell the loader to start.
var loader = new PxLoader(),
backgroundImg = loader.addImage('images/headerbg.jpg'),
treesImg = loader.addImage('images/trees.png'),
ufoImg = loader.addImage('images/ufo.png');
// callback that will be run once images are ready
var canvas = document.getElementById('sample1-canvas'),
ctx = canvas.getContext('2d');
ctx.drawImage(backgroundImg, 0, 0);
ctx.drawImage(treesImg, 0, 104);
ctx.drawImage(ufoImg, 360, 50);
// begin downloading images