Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created September 30, 2014 19:38
Show Gist options
  • Save walterdavis/58648f68204d85abcea9 to your computer and use it in GitHub Desktop.
Save walterdavis/58648f68204d85abcea9 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery Without Duplication</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div>
Much page follows... maybe some partials are included. Now you want to load jQuery again for whatever reason.
</div>
<script type="text/javascript">
// safely load jQuery when you aren't certain it already exists
if(!window.jQuery){
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment