Why bother falling back to a local copy?
There may be times when the CDN version cannot be loaded. For example:
- you're doing development on a disconnected computer
- a country or workplace network blocks the CDN
- various connectivity issues
How to load the fallback version if the CDN version cannot be loaded
Add this to your HTML document template:
This example uses jQuery 1.6.1, which is the current version at the time of writing this post, using the Google CDN. Note the src starts with // and not http:// If you page is hosted on an https:// URL it will use the https:// version of the URL; on http:// it will use the http:// version.
The document.write uses an escaped string to avoid issues with the closing </script> tag and uses unescape() to remove this escaping.
Note that I have tested this on IE6, IE7, IE8, Chrome and mobile Safari on the iPhone Simulator both connected and disconnected and the falback works fine in these browsers.