Skip to content

Instantly share code, notes, and snippets.

View JoxieMedina's full-sized avatar
🏠
Working from home

Darwin Medina JoxieMedina

🏠
Working from home
  • CTI
  • Honduras
View GitHub Profile
@JoxieMedina
JoxieMedina / scriptLoaderES6.js
Last active August 10, 2018 01:47 — forked from jtpaasch/loader.js
Javascript module for loading scripts asynchronously.
import {uniqueId} from 'lodash' // optional
/**
* @param {String} file The path of the file you want to load.
* @param {Function} callback (optional) The function to call when the script loads.
* @param {String} id (optional) The unique id of the file you want to load.
*/
export const loadAsyncScript = (file, callback, id) => {
const d = document
if (!id) { id = uniqueId('async_script') } // optional
if (!d.getElementById(id)) {