JSPM

@jongleberry/load-script

1.0.2
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 1
    • Score
      100M100P100Q28627F
    • License MIT

    Script loader with promise & requestIdleCallback support

    Package Exports

    • @jongleberry/load-script

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jongleberry/load-script) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    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.