What would be a good way to attempt to load the hosted jQuery at Google (or other Google hosted libs), but load my copy of jQuery if the Google attempt fails?
I\'m n
This seems to work for me:
hello jQuery
The way it works is to use the google
object that calling http://www.google.com/jsapi loads onto the window
object. If that object is not present, we are assuming that access to Google is failing. If that is the case, we load a local copy using document.write
. (I'm using my own server in this case, please use your own for testing this).
I also test for the presence of window.google.load
- I could also do a typeof
check to see that things are objects or functions as appropriate. But I think this does the trick.
Here's just the loading logic, since code highlighting seems to fail since I posted the whole HTML page I was testing:
if (window.google && window.google.load) {
google.load("jquery", "1.3.2");
} else {
document.write('