views:

974

answers:

4

This one is a case of not doing your homework.:-)

Apart from dynamic loading advantage, does it make sense to include a JavaScript library(jQuery in my case ) from a Google server when I can load it from my server as a single file comprised of the 19kb jQuery zip file + the additional JavaScript code I have written – all compressed with a JS compressor and served HTTP deflated.

With Google server I’ll have 2(parallel) HTTP round trips. One to get the jquery file and the other to get the site JavaScript code. One 19kb and the other say 20-25kb. Under normal circumstances it would be a single 30-35kb download from my site.

+1  A: 

Is this a real question? Just make sure your Cache-Control in your HTTP headers are properly configured and the end user's client will only pull it once. This is an absolutely trivial amount of data.

Andrew
Even with cache control + ET tag a new user will have to download 30kb of data.
Cherian
Cherian, this page alone is 27.61kb. Unless you're expecting users to hit-and-run with one or two page views, each rendered page will quickly end up outweighing the size of your jslibs. Either way, even with 10000 users that's 30 MEGS. If your server can't serve that, get a new one.
Andrew
That should read 1000 users not 10000. Got a little happy with my zero key.
Andrew
+8  A: 

Consider that a jQuery script downloaded from the google CDN might well already be cached on a visitor's browser, since it has consistent headers and cache control no matter where it is downloaded from. Hence, on average most users will only have to download your site-specific javascript scripts. Also, CDN generally have faster response times than single servers, since they respond from a server nearest to your location.

There is no cut and dry answer to your question, as both approaches offer good performance on modern connections. You should profile your system under duress and see what solution offers the best results (and if such optimization is even needed).

Eran Galperin
A: 

Are you sure scripts would be downloaded in parallel? This example from Cuzillion seems to be saying that only IE8 can do that.

Also worth finding out is how many of your pageviews are first time visitors and how many have visited the site before to help you decide how much caching will influence download time. If you have a significant number of first time visitors it's probably worth skewing it in their favour to make the first time experience as fast as possible.

Sam Hasler
+1  A: 

A benchmark test done by httpwatch for js files from google.

http://blog.httpwatch.com/2008/11/27/google-adds-https-support-to-the-ajax-libraries-api/

Cherian