Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@segment/load-script

segmentio69.4kSEE LICENSE IN LICENSE1.0.1

Dynamically and asynchronously load a script file.

DOM, iframe, load, script

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.

changelog

1.0.1 / 2016-05-09

  • Add npm authing to circle.yml (for automatic tag publishing)

1.0.0 / 2016-05-07

  • Remove Duo support
  • Set up CI/test harness

0.1.2 / 2014-06-24

  • wait til next frame to callback in all cases

0.1.1 / 2014-06-12

  • append script after event listeners are added for IE
  • use script-onload component

0.1.0 - September 24, 2013

0.0.1

:sparkles: