Simple assets preloader
MIT License
prelude.js is a simple and flexible preloader works with CommonJS, AMD and <script>
.
$ npm install --save prelude-js
or
$ bower install --save prelude-js
<script src="/path/to/prelude.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const loader = new Prelude()
loader.add([
{ from: '/images/picture.jpg' },
{ from: 'http://example.com/sample.png' },
])
loader.on('end', result => {
document.body.appendChild(result.get('picture'))
document.body.appendChild(result.get('sample'))
})
})
</script>
Prelude also supports CommonJS, AMD style including options. This is more modern way:
const domready = require('domready')
const Prelude = require('prelude')
domready(() => {
// preload assets
const loader = new Prelude()
loader.add({ from: 'http://cdn.example.com/bgm.mp3' })
loader.on('end', result => {
// assets ready
const track = result.get('bgm')
track.play()
})
})
This is open-source project. Feel free to open new issue!
Maintained by Yasuaki Uechi
Licensed under MIT License