Created
October 29, 2017 11:03
-
-
Save fnumatic/2643c060b5c2779c14e839c1e3435a38 to your computer and use it in GitHub Desktop.
This file contains 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
var _loadScript = function(path){ | |
var script= document.createElement('script'); | |
script.type= 'text/javascript'; | |
script.src= path; | |
document.head.appendChild(script); | |
}; | |
function fetchLocal(url) { | |
return new Promise(function(resolve, reject) { | |
var xhr = new XMLHttpRequest | |
xhr.onload = function() { | |
resolve(new Response(xhr.responseText, {status: xhr.status})) | |
} | |
xhr.onerror = function() { | |
reject(new TypeError('Local request failed')) | |
} | |
xhr.open('GET', url) | |
xhr.send(null) | |
}) | |
} | |
fetchLocal('url/lib.js') | |
.then(response => response.text()) | |
.then(text => eval(text)) | |
.then(() => { /* now you can use your library */ }) | |
//document.write, goog.require etc | |
var CLOSURE_DEFINES = {'goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING': true}; | |
document.write('<script src="url/lib.js"></script>'); | |
goog.require("foo.core") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment