Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created October 17, 2012 20:52
Show Gist options
  • Save konsumer/3908104 to your computer and use it in GitHub Desktop.
Save konsumer/3908104 to your computer and use it in GitHub Desktop.
<html>
<head>
</head>
<body>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
window.imported={};
// synchronous require for CommonJS
function require(name){
if (!window.imported[name]){
$.ajax(name + '.js', {
cache: false,
async:false,
success: function(data, textStatus, jqXHR){
window.imported[name] = new Function('var exports={};' + data + ';return exports;')();
},
error: function(jqXHR, textStatus, errorThrown){
window.imported[name] = false;
console.error(errorThrown);
}
});
}
return window.imported[name];
}
var fib = require('../janrain/fib');
console.log(fib.fib(4000));
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment