Skip to content

Instantly share code, notes, and snippets.

@danheberden
Created November 11, 2011 21:02
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 danheberden/1359247 to your computer and use it in GitHub Desktop.
Save danheberden/1359247 to your computer and use it in GitHub Desktop.
jQuery Include Snippet
<script>
(function(){
// Look for a jqversion query parameter and grab any following version.
// Limit to digits and letters to prevent any XSS attempts
var verMatch = /jqversion=([\w\.]+)/.exec( location.search ),
// our matched version, e.g., 1.6.4 or 1.7rc1
version = verMatch && verMatch[1],
src;
if ( version ) {
// version was specified, use jQuery's CDN to acccess non-mininfied betas and RCs
src = 'code.jquery.com/jquery-' + version;
} else {
// nothing was specified, use the Google CDN (or jQuery's or Microsoft's) with a minified copy
src = 'ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min';
}
// create the script tag
document.write( '<script src="//' + src + '.js"><\/script>' );
})();
</script>
<script>
// Use a local copy, incase the above didn't load
if ( !window.jQuery ) {
document.write( '<script src="/scripts/jquery-1.7.0.min.js"><\/script>' );
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment