Loads a script only once, calls back when ready multiple times. Like segmentio/load-script
, but loads a script once per url, and doesn't load the script again if it is already on the page.
Install with component(1):
$ component install segmentio/load-script-once
var load = require('load-script-once');
load('//www.google-analytics.com/ga.js');
Loads in the Google Analytics library (assuming it isn't already on the page)
var load = require('load-script-once');
load({
http : 'http://www.google-analytics.com/ga.js',
https : 'https://ssl.google-analytics.com/ga.js'
});
Loads in the right URL depending on the protocol.
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
.
MIT