views:

141

answers:

2

Curious if there was a simple way to have a fail-safe on google.load()

The likely hood that google can't deliver the file but I can is pretty slim but I thought it might be interesting to have my own server be able to provide a failover in case the request bombs or timesout or something.

any thoughts?

I'm using MS visual studio 2008 / C#

A: 

The chances of this are small enough that this probably falls into the category of over-thinking things. Realistically speaking, your own server is vastly more likely to go offline than Google's setup. Unless you're dealing with millions of dollars worth of transactions on your site on a regular basis, this is going to be an unnecessary (and probably unreliable) bit of engineering.

There is a callback parameter for google.load, however, this gets called on success rather than failure. I'm not sure what happens on failure because I've never been able to load the JS API but not the rest of the Google-hosted JS files. And that's kind of the trick. If you can call google.load in the first place, you can be pretty sure that the Google servers are reachable. If, for some insane reason, the Google servers are down, then the google object will never get defined in the first place. I don't know if there's any officially documented way to detect failure, but I suppose you could just detect if the google object is defined and load your own hosted version of the scripts yourself at that point.

If you do go down that route, you can test it by pointing google.com to something bogus like 0.0.0.0 in your hosts file. I would not be surprised if there are still issues at that point with things like onload events, since the event might have been fired before the event handler even gets registered in the fail-over case.

Bob Aman
I understand that google's servers are far more dependable than my own most likely... but I don't like the idea of letting them determine the stability of my site. Since jquery is becoming so important I like to keep the control (but share the bandwidth ;-) Thanks for the feedback.
tnriverfish
Fair enough. Though the point that the other guy made about Google domains being blocked is somewhat mitigated by the use of the `googleapis.com` hostname. Though you might still get blocked by an overzealous content filter. There's a lot of different reasons why an HTTP request might fail really. It's rarely worth the effort to account for all of them because, most of the time, the error-recovery process isn't perfect or well-tested or it's just straight-up unrecoverable. Consider that your time is finite and that engineering resources are probably better spent on other things.
Bob Aman
+1  A: 

I think this is what you are looking for http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-goo

Ritesh M Nayak
great. thanks. I figured someone had touched on it but didn't find it.
tnriverfish