Created
October 5, 2016 10:11
-
-
Save madila/ea67f5f922a782a94a32c5f4930f0f20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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