All Projects → segmentio → Load Script

segmentio / Load Script

Licence: mit
Load a Javascript file asynchronously.

Programming Languages

javascript
184084 projects - #8 most used programming language

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].