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 times开发者_如何学JAVAout or something.
any thoughts?
I'm using MS visual studio 2008 / C#
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.
精彩评论