dynamic-script
Extremely simple dynamic script loader with promise API
Companion to dynamic-style
Goals
- Simple and readable source code
- Small API
- Fully tested
Install
$ npm install dynamic-script
Usage
const loadScript = require('dynamic-script')
loadScript('https://url.com/script.js')
.then(() => console.log('loaded successfully'))
.catch(() => console.log('script failed to load'))
const elem = await loadScript('https://url.com/script.js')
elem.src
Configure by passing a script element. It will be used instead of creating a new element.
const scriptTag = document.createElement('script')
scriptTag.async = false
await loadScript('https://url.com/script.js', scriptTag)