require-sdk

JavaScript library for making sure given SDK is loaded and executed. Designed for popular APIs like Youtube, Rdio, Soundcloud etc.

npm install require-sdk
1 downloads in the last day
11 downloads in the last week
31 downloads in the last month

require-sdk

JavaScript library for making sure given SDK is loaded and executed. Designed for popular APIs like Youtube, Rdio, Soundcloud etc.

See tests.js for examples.

Install

$ npm install require-sdk

Usage

requireSDK = require('require-sdk')

requireFoo = requireSDK('http://foo.com/api.js')

requireFoo(function () {
  // foo.com/api.js loaded
  Foo('do something')
})

requireFoo(function () {
  // you can add multiple callbacks.
  // it lets you easily wrap all your SDK dependent code
  // and makes your code look meaningful
})

Check if it's already loaded:

var requireFoo = requireSDK('https://www.youtube.com/iframe_api', 'YT') // Doesn't attempt to load if window.YT is defined

Manually trigger the load event if custom conditions required:

var requireFoo = requireSDK('https://youtube.com/iframe_api', 'YT')
window.onYouTubeIframeAPIReady = requireFoo.trigger() // load event delays until onYouTubeIframeAPIReady is called

Libraries Based On It

npm loves you