Skip to content

Instantly share code, notes, and snippets.

@madila
Created October 5, 2016 10:11
Show Gist options
  • Save madila/ea67f5f922a782a94a32c5f4930f0f20 to your computer and use it in GitHub Desktop.
Save madila/ea67f5f922a782a94a32c5f4930f0f20 to your computer and use it in GitHub Desktop.
/**
* Created by Madila on 05/10/2016.
*/
class Async {
constructor(id) {
this.url = url;
this.id = id;
}
add(url) {
let doc = document;
if (doc.getElementById(this.id)) {return;}
let fjs = doc.getElementsByTagName(script)[0],
js = doc.createElement(script);
js.src = url;
js.async = true;
js.onload = js.onreadystatechange = function() {
console.log(id+'-loaded', [id]);
};
id && (js.id = id);
fjs.parentNode.insertBefore(js, fjs);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment