Created
January 19, 2011 05:05
-
-
Save aaronpowell/785716 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
<!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