@jongleberry/load-script

Script loader with promise & requestIdleCallback support

Stats

StarsIssuesVersionUpdatedCreatedSize
@jongleberry/load-script
1.0.24 years ago4 years agoMinified + gzip package size for @jongleberry/load-script in KB

Readme

@jongleberry/load-script

Build Status codecov

Script loader with:

  • Promise support
  • requestIdleCallback 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 URL
  • options:
    • type
    • charset
    • id
    • noModule
    • async
    • defer
    • timeout - timeout passed to requestIdleCallback, falling back to setTimeout. Set to 0 to load JS in at least the next tick.

Returns the script element when it's resolved.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.