Correct me if I'm wrong, but the high speed of the CDN isn't the only (or even primary) benefit. In my opinion, browser caching is a much bigger plus. As soon as a user downloads one of these hosted libraries (by visiting a site that calls for it), their cache is primed for every other relying site they visit. Correct?
Assuming this is true, why would someone use the Google API Loader javascript call ("google.load") instead of linking to the file directly? Linking directly allows the browser to use its cache, while using google.load needs to make an external call to Google, bypassing a big benefit of the caching.
"Correct me if I'm wrong, but the high speed of the CDN isn't the only (or even primary) benefit. In my opinion, browser caching is a much bigger plus. As soon as a user downloads one of these hosted libraries (by visiting a site that calls for it), their cache is primed for every other relying site they visit."
It depends on the CDN and what cache information it returns. I'm not going through all the links and verifying that they all return correctly. I do recall Yahoo's YUI documentation page promising the use of far-future Expires which means that the browser very likely never even hits the CDN, but nothing stops the CDN from using E-Tags instead, which is still pretty fast but does manifest as a hit on the CDN they could track. That said, it's entirely possible that every link there uses far-future Expires.
Personally, I'd just grab the file and use far-future Expires myself. If you've got a web application that uses code that way, odds are this is not going to be your bottleneck anyhow; far-future Expires just as thoroughly fails to hit your server as it fails to hit the CDN.
Content-Type: text/javascript; charset=UTF-8
Last-Modified: Tue, 09 Feb 2010 23:05:02 GMT
Date: Mon, 01 Mar 2010 00:09:20 GMT
Expires: Mon, 28 Feb 2011 21:55:22 GMT
Cache-Control: public, max-age=31536000
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Server: sffe
Content-Encoding: gzip
X-XSS-Protection: 0
200 OK
It looks like Google is setting an expires for 1 year in the future, meaning (I believe) that the browser will use the cached copy. So, by using these libraries, you have a decent chance that a brand new visitor will arrive with a warm cache, thereby speeding up that initial page load (and first impression!) a tiny fraction.
according to various resources google.load() can do the work asynchronously so the whole page load will not be stalled by the <script> loading. Also you may want to load that .js only on demand not on page load.
That said, IMHO most pages are fine with hardcoded <script> though.
Assuming this is true, why would someone use the Google API Loader javascript call ("google.load") instead of linking to the file directly? Linking directly allows the browser to use its cache, while using google.load needs to make an external call to Google, bypassing a big benefit of the caching.