loadx
v0.2.0
Published
Load image, CSS, and JavaScript files, using the Promise API.
Downloads
177
Readme
loadx
Simple asset loader that allows loading of image, CSS, and JavaScript files, using the Promise API, and fires a callback upon success or failure.
- 🚚 Load JS, CSS or Image
- 🚀 Cache results
- ⏳️ Works beautifully with promise and async/await
- 📦️ Just 400 bytes of gzipped ES3
Install
$ npm install --save loadx
Usage
import loadx from 'loadx';
async function loadResources() {
// loading a JavaScript resource
await loadx.js('https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js');
// from here, you can start using axios regularly
const user = await axios.get('/user?ID=12345');
// you can load CSS...
await loadx.css('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css');
// ...and image as well
const imageElement = await loadx.img('https://picsum.photos/200/300');
}