Created
February 1, 2011 00:22
-
-
Save cowboy/805146 to your computer and use it in GitHub Desktop.
Google CDN -> jQuery CDN fallback
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
<!-- | |
See JSFiddle: | |
http://jsfiddle.net/cowboy/6asBw/ | |
--> | |
<!-- unminified --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | |
<script> | |
// If jQuery failed to load from the Google AJAX APIs CDN... | |
window.jQuery || (function(doc, script, matches){ | |
// Get the preceding script tag. | |
script = doc.scripts; | |
script = script[ script.length - 2 ]; | |
// Parse the requested jQuery version number and whether or not it was minified. | |
matches = script.src.match(/\/(\d+\.\d+)(\.0)?(\.\d+)?\/jquery(\.min)?\.js$/); | |
// If there were matches, load the jQuery CDN version of the specified script. | |
// Note that Google CDN version 1.4.0 maps to jQuery CDN version 1.4 and that | |
// the jQuery CDN doesn't handle 1 or 1.4 the same way to Google CDN does, so be | |
// sure to specify the full x.y.z version! | |
matches && doc.write('<script src="http://code.jquery.com/jquery-' + matches[1] + ( matches[3] || '' ) + (matches[4] || '') + '.js"><\/script>'); | |
})(document); | |
</script> | |
<!-- minified --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | |
<script>/*cowboy-jquery-cdn-fallback*/window.jQuery||(function(c,a,b){a=c.scripts;a=a[a.length-2];b=a.src.match(/\/(\d+\.\d+)(\.0)?(\.\d+)?\/jquery(\.min)?\.js$/);b&&c.write('<script src="http://code.jquery.com/jquery-'+b[1]+(b[3]||"")+(b[4]||"")+'.js"><\/script>')})(document)</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment