Here are the benefits of using the Google hosted jQuery libraries:
- By using the Google hosted jQuery libraries, since many applications use the Google infrastructure, when someone comes to your application, the Google hosted files may already be loaded into the visitor’s browser cache.
- The subtle performance issue associated with the transfer of cookie data is revolved because your domain is different from Google’s (i.e.,: not google.com), so no cookie data or other verbose headers will be sent up, saving precious bytes.
- By loading the jQuery libraries from Google, the HTTP requests for those libraries don’t compete with the requests for assets from your domain, speeding up the overall page load time:
“Browsers typically limit the number of concurrent HTTP connections per server to be 2. If a browser session has two HTTP connections already [for a given server], any further connection requests will have to wait until one of these two HTTP connections is finished.” — Source: OpenAjax Alliance - Google hosted files are compressed using GZIP.
- Google has a distributed CDN at various points around the world, so the files are “close” to the visitor.
- Google servers are fast.
Here’s the drawback:
- In the highly unlikely event that Google’s CDN goes down, the missing jQuery libraries will prevent your jQuery dependent page from loading correctly. The fix for this is to alternatively load the jQuery library from somewhere else. Microsoft now hosts the jQuery library on their CDN.
Here’s an example of alternate loading. Try loading from Google. Check for the presence of the jQuery function. If it isn’t there, load jQuery from Microsoft.
<script type=”text/javascript”>
if (typeof jQuery !== ‘function’) {
document.write(‘<scri’ + ‘pt type=”text/javascript” src=”http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js”></scri’ + ‘pt>’);
}
</script>
If both Microsoft and Google are down, then the world must be at an end, so your site not loading is the least of your problems.