Here’s a nice snippet of JavaScript for including Google-hosted jQuery with fallback.

Because you never know when Google won’t be available, either due to network congestion, failure, or other reasons. In fact, Google’s domain is banned in some countries, so best to provide a fallback script.

Method 1

Place this code in the <head> section or just before the closing </body> tag:

Edit the path “/js/jquery.min.js” to match the location of jQuery, either a local copy on your server or an alternate external location such as a CDN. Note that the latest version of jQuery also is available via the jQuery site, located at:

http://code.jquery.com/jquery-latest.js

Method 2

Here is an alternate version of the previous method that uses the same basic principle but with more concise syntax. To include Google-hosted jQuery with a local/alternate fallback, add the following code snippet: