Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created October 17, 2012 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save konsumer/3907755 to your computer and use it in GitHub Desktop.
Save konsumer/3907755 to your computer and use it in GitHub Desktop.
window.exports={};
window.imported={};
// synchronous require for CommonJS
function require(name){
if (!window.imported[name]){
var xhrObj = createXMLHTTPObject();
// open and send a synchronous request
xhrObj.open('GET', name + ".js", false);
xhrObj.send('');
var se = document.createElement('script');
se.type = "text/javascript";
se.text = xhrObj.responseText;
document.getElementsByTagName('head')[0].appendChild(se);
window.imported[name] = window.exports;
}
return window.imported[name];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment