JSPM

@segment/load-script

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10598
  • Score
    100M100P100Q139350F
  • License SEE LICENSE IN LICENSE

Dynamically and asynchronously load a script file.

Package Exports

  • @segment/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 (@segment/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

load-script

Sauce Test Status

Component which asynchronously loads a JavaScript file by appending a script tag to the DOM.

Installation

$ npm install @segment/load-script

Examples

var load = require('@segment/load-script');

load('//www.google-analytics.com/ga.js');

Load in a URL depending on the current protocol.

var load = require('@segment/load-script');

load({
  http: 'http://www.google-analytics.com/ga.js',
  https: 'https://ssl.google-analytics.com/ga.js'
});

API

loadScript(src || options, callback)

Load the given script either by passing a src string, or an options object:

{
  src: '//example.com/lib.js', // same as `src` string
  http: 'http://example.com/lib.js', // `src` to load if the protocol is `http:`
  https: 'https://ssl.example.com/lib.js' // `src` to load if the protocol is `https:`
}

You can also pass in a callback that will be called when the script loads with err, event.