dynamic-script

1.0.3 • Public • Published

dynamic-script

Greenkeeper badge Travis badge standard badge npm

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')
 
// url is set as <script src="${url}">
loadScript('https://url.com/script.js')
  .then(() => console.log('loaded successfully'))
  .catch(() => console.log('script failed to load'))
 
// resolves with the appended script element
const elem = await loadScript('https://url.com/script.js')
elem.src // https://url.com/script.js

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)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    7
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    7
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i dynamic-script

Weekly Downloads

7

Version

1.0.3

License

MIT

Unpacked Size

5.13 kB

Total Files

7

Last publish

Collaborators

  • kayleepop