Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created January 19, 2011 05:05
Show Gist options
  • Save aaronpowell/785716 to your computer and use it in GitHub Desktop.
Save aaronpowell/785716 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Loader</title>
<script type="text/javascript">
//assume this is in an external file, so we do an external here
var loader = (function() {
var scripts = [];
var ret = {
add: function(src) {
if(!scripts.indexOf(src)) {
scripts.push(src);
}
return ret;
},
render: function() {
while(scripts.length) {
var src = scripts.pop();
document.write("<script type='text/javascript' src='" + src + "'></" + "script>");
}
return ret;
}
};
return ret;
})();
</script>
<script type="text/javascript">
loader.add('/path/to/jquery.js');
</script>
</head>
<body>
<h1>Hello World!</h1>
<script type="text/javascript">
loader.add('/path/to/my-script.js');
</script>
<script type="text/javascript">
loader.render();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment