A dead simple image preloader for the web
npm install preloadifyjs
import preloadify from "preloadify"
`
as a script tag:
`html
`
as a commonjs module:
`js
const {preloadify} = require("preloadify");
`
and as a AMD require:
`js
require(['preloadify'], function ({preloadify}) {
preloadify(...);
});
`
API 🐱👤
As said earlier, this package is __dead__ simple.
`js
async function dummyFunc() {
await preloadify([src1, src2]);
// OR
await preloadify('src1');
// Images are preloaded 🎉
//
will instantly load the image
}
function dummyFunc() {
preloadify([src1, src2]).then(() => {
// Images are preloaded 🎉
})
}
`
As easy as that.
There is a also an optional 'options' argument.
It can have two properties:
__oneach__:
`js
preloadify([src1, src2], {
oneach(src) {
// Called when a single image fully loads
// and passes in that image's src
console.log(Image with source ${src} was loaded);
}
});
`
__onprogress__:
`js
preloadify([src1, src2], {
onprogress(percents, [done, total]) {
// Called the same time as oneach
// Provides info on loading progress
console.log(Loading: ${percents}%);
// OR
console.log(Loading: ${done} of ${total}});
}
});
``