I'm launching my own site tomorrow, and I'm expecting a couple hundred visits.
I wrote this script based on what PHP.net told me:
<?
$f = fsockopen("code.jquery.com", 80, $errno, $errstr, 30);
if(!$f){
echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>'; }
else {
echo '<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>'; }
?>
Basically, if code.jquery.com's CDN is ever down (like it was about 20 minutes ago), then the Google API Library will kick in. I've tried it whilst jQuery was up, and it works, but just in case it goes down again, will this script actually work? (by switching over to Google's library) I can't really test it, I'd have to make code.jquery.com go offline. lol.
I'd do CSS replacements, but my entire site is based off of jQuery and Ajax, so I kind of really need it to function at all times. I'd host it on my own site, but my website isn't anywhere as fast as code.jquery.com or googleapis.com when they're running fine.
Thanks alot! Any responses greatly appreciated :)
Why would you do this server side? it would make more sense for this to be done client side:
This first tries to load the library from google. If it loads, then
window.jQuery
will be available. If not, then it tries to load from code.jquery.com. You can even put in another after those two to load a local version if neither load: