views:

96

answers:

3

Hi

So I heard good reasons why to use the jquery hosted on google because of caching. But I am not sure about jQuery UI though.

I am guessing that the jQuery UI file hosted on google has every single extension and plugin (such as Draggable, etc).

So is that not kind of a waste if say your only using only jQuery UI tabs? to get all that other stuff with it.

Also I see they have some of the templates up for the css files. I am guessing the caching would be the main advantage of using the hosted file.

+2  A: 

That depends. If the file is already in the user's cache then it's going to be quicker than downloading the independent class from your server because parse speed > download speed. If the google-hosted file isn't cached by the user then, assuming a connection rate matching Google's servers (not taking into account saving the DNS lookup :-)), it would be quicker to fetch it from your own server.

Andy E
But the fact is that odds are, the user has been to another site that has used Google's jQuery library within the last week or so, so the odds are that they will have it cached.
Christian Mann
Ya thats what I was thinkings. It kinda hard to decide in some cases.
chobo2
+4  A: 

It's worth it. The blog post for jQuery's last update used the word "performance" more than any other -- and for good reason. The library isn't small, so performance can be a problem.

Hosting your .js on Google is one way to count on jQuery being the lingua franca of the JavaScript world and it could save you valuable download time in browser. Remember, scripts block parallel downloads so any time your user spends downloading the .js from you is time they can't spend downloading something else.

The downfall is that Google could perhaps go down, but there's already industry talk about redundancy and roll-over servers to mitigate that concern.

editor
Well 2 questions regarding parallel downloads. First if you use jquery ui and jquery off googles hosting. Would that not be a block parallel download( getting 2 scripts off the same server)? I also take care of that issues through some called http combiner where it dynamically takes all my javascript files and makes them into one javascript file when the user comes. So only one download would happen. So is its till worth it?
chobo2
@chobo: Actually, downloading of scripts that are part of the document structure at parse-time halts document parsing anyway, so scripts can't download simultaneously. For instance, if jQuery were included first, followed by jQueryUI, they would be downloaded and parsed one after the other in the order they appear in the document.
Andy E
+1  A: 

Google properly sets up caching the JQuery library for the widest possible range of browsers, using Cache-Control, Last-Modified, Expires, Age, and Date. It'll reliably cache on every common browser. In addition to this, the server is geo-locational - the user will always do the initial download from the closest possible server to them.

And as @editor said, browsers will block parallel resource downloads from the same hostname. Your sites javascript will download in parallel at the same time as the JQuery library downloads from googles domain giving you those additional precious milliseconds :)

You also delegate the bandwith costs to Google. Say 10000 unique vistors hit your page each day - thats a minimum of ~30Mb. A month? ~878Mb. A year? ~313Gb.

TkTech