@jongleberry/load-script
v1.0.2
Published
Script loader with promise & requestIdleCallback support
Downloads
7
Maintainers
Readme
@jongleberry/load-script
Script loader with:
Promise
supportrequestIdleCallback
support
Installation:
npm install --save-dev @jongleberry/load-script
Example:
import loadScript from '@jongleberry/load-script'
loadScript('https://www.googletagmanager.com/ns.html?id=GTM-XXXX', {
timeout: 1000
}).catch((err) => {
console.error(err.stack)
})
API
const script = await loadScript(src [, options])
src
- JS source URLoptions
:type
charset
id
noModule
async
defer
timeout
- timeout passed torequestIdleCallback
, falling back tosetTimeout
. Set to 0 to load JS in at least the next tick.
Returns the script element when it's resolved.