Skip to content

Instantly share code, notes, and snippets.

View briangranatir's full-sized avatar

Brian Granatir briangranatir

View GitHub Profile
@micahjon
micahjon / loadScript.js
Last active November 5, 2017 12:59
Promise-based Asynchronous Script Loader
/**
* Loads javascript file by url and saves reference to it by name, so it's not loaded again
* @param {string} name Name of js library
* @param {string} url Url to js library
* @return {promise} Resolves when library is loaded
*
* Based on example by Brad Berger: https://bradb.net/blog/promise-based-js-script-loader/
* Extended w/ global variable to keep track of previously loaded scripts.
* Removed support for loading several independent scripts at once via Promise.all()
*