jQuery hosted on Google and some implications for developers
May 28th, 2008
I finally made the long discussed flip over to jQuery. It took me about 4 and a half minutes. It should have been a 30 second process, but I had a few lightbox images relationships named incompatibly. Anyhow, all fixed up. I also decided to implement the much talked about Google hosted Javascript library. In a nutshell, Google is hosting some popular Javascript libraries. The idea is that if enough people are using the hosted libraries, then there’s a good chance that your visitor has already locally cached the files, and your page will (give the illusion of) load faster.
As a handy extra, they take care of compressing and minifying for you, and are committed to keeping a library online permanently after it is hosted.
That said, I’m not sure how long I’ll keep it. There are a few things that I think every responsible webmaster has to think about first. Personally, I would only use it as part of an informed company strategy (I could see a savings on a big site like ExpressionEngine.com in terms of bandwidth and perceived load time). But there are still some downsides I just haven’t fully reconciled yet. Let me address the three most relevant ones that I see.
What if Google goes down?
Google? Not likely, but this is probably the most valid argument I can think of. I suppose if one were really concerned about it, they could use:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
if (!jQuery)
{
// jQuery obviously hasn't been loaded... let's get on that shall we...
document.write('<script type="text/javascript" src="/js/jquery.min.js"></script>');
// oh, and don't flame me for document.write... its just an example
}
</script>
But the truth is that I’m not going to bother doing that here. Without javascript DerekAllard.com runs just fine anyhow.
By allowing Google to put Javascript on your page you are allowing them to over-ride or re-write your content by manipulating your DOM
This is true, and of course is a risk with any remotely loaded script or content (think of all those Google Ads… now there is a hacker’s wet-dream). I already allow Google Analytics here, so its a risk I’ve already thought about, and am prepared to take.
What about privacy? Google is collecting a lot of data.
Also valid of course. Firstly, I’m already giving them access to that data via analytics, but the broader question I suppose is what do they do with all the data they collect. For now, I’m comfortable with their privacy policies and published data collection protocols, but I admit to being uncomfortable with any one agency having all that data.
Also, there were already a lot of sites that were pointing to Google Code to load the Javascript anyways, so this is almost just like formalizing something many people were doing anyhow.
Now, for frameworks like CodeIgniter, I see another major benefit, albeit, on a pretty selfish level. As has been discussed, CodeIgniter is getting a jQuery library added in. One of the really pain in the ass things about building this library, has been trying to figure out the most elegant ways to include the library source files. Adding the whole jQuery library to the CI download isn’t really a good option; not everyone will want them, and every dev has different preferences about where they keep site assets anyhow. With the advent of this API, we could conceivably use google as a default source dir, and allow devs to over-ride that with a config or initialization setting. Let me just caution now that this is a totally “off the top of my head” thought, and I’m not saying CodeIgniter necessarily will do this, only that its something worth exploring.
I haven’t fully worked through the implications in my head yet (those of you who know me know that that might take a long time… I’m not the smartest guy), but the experiment has started. Google has the potential to do something really neat here. In a perfect world, properly implemented, file size will become nearly a non-issue when selecting a javascript library, and bundled apps could rely on a robust, stable delivery for scripts. I’m not naive enough to think that’ll ever fully come to pass, but the goal is admirable.
This entry was made on May 28th, 2008 @ 8:23 and filed into CodeIgniter, Javascript.

Michael Wales wrote on May 28th, 2008 @ 8:42
It’s definitely nice to see Google takes this step and formalize the situation, like you said, “a lot of people were doing this anyways.”
There are numerous concerns with doing so - but I see this “cloud computing” really taking off. A lot of the bigger companies are making available assets and resources the little man just did not have 3-4 years ago.
Look at Amazon with all of their amazing services - it doesn’t get much better than that. Instant scalability without having to worry about how you’re going to get the new server through the door? I’m in…
Yahoo has been offering their bandwidth for awhile now - in loading the YUI files from their servers. Google’s simply taken this a step further by supporting a lot more than YUI.