views:

197

answers:

1

I've recently moved a site over to use the Google AJAX Libraries instead of hosting the library js files myself. At the moment I'm using the Google recommended approach:

<script type="text/javascript" src="http://www.google.com/jsapi?key=MYAPIKEY"&gt;&lt;/script&gt;
<script type="text/javascript">google.load('jquery', '1.3.2');</script>

But it seems a little silly to me to include an extra JavaScript file, just so I can call another script file.

My question is, is there actually any advantage to calling these files via google.load() as opposed to simply including them via script tag like so:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;

My main reasons for using the Google hosted libraries are the speed of their CDN/edge caching systems; am I still getting those benefits if I link directly to the file?

+1  A: 

the main advantage for using the loader api is that you will prevent blocking by the browser when its doing the initial downloads. Browsers can only download between 2 & 10 things at a time so if there is blocking it will give bad user experience

Steve Souders and the Yahoo! Exceptional Performance team have done a lot of research into this to get faster websites. Nick Zakas (JavaScript guru) blogged about using Steve's ideas here

AutomatedTester
But that HTTP connection limit only applies per domain, so if I link to the file on Google's servers it's not relevant anyway - content from my server will still download concurrently. Plus, I'm still synchronously loading the JS for the API itself, which is only marginally smaller than the jQuery JS.
Mark B
If its just for jQuery then I would just use the script tag because it will still the same CDNs. If you wanted to use jQuery and jQuery UI and <insert other thing you want download here> then the API would be more benefitial
AutomatedTester
Ah, I see, so you're saying that if I was loading *multiple* libraries from Google then the API loader would allow me to do that in a non-blocking way, but it's not really worth it just for one library. Thanks!
Mark B