Skip to content

Instantly share code, notes, and snippets.

@jonathanstark
Last active December 13, 2015 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanstark/4993767 to your computer and use it in GitHub Desktop.
Save jonathanstark/4993767 to your computer and use it in GitHub Desktop.
Snippet of javascript code that will append external script files programmatically. Intended for responsive web sites where maximum progressive enhancement is desired. Don't want to make needless http requests or load external javascript on devices that can't (or shouldn't) execute javascript. NOT DEPENDENCY SAFE! Scripts will load asynchronousl…
<html>
<head></head>
<body>
<!-- All your kewl content goes here -->
<!-- Append javascript programatically so we don't make needless http requests -->
<script>
(function(){
var goodBrowser = function() {
// Check for features and return true if browser has everything you need
return true;
}
if(goodBrowser()) {
document.write('<script src="./js/script1.js"><\/script>');
document.write('<script src="./js/script2.js"><\/script>');
}
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment