Google-served JavaScript libraries
May 27th, 2008 by Thomas Fuchs, 10 comments »Thanks to Dion Almaer and Google, you can now use served-off-googles-infrastructure versions of your favourite JavaScript libraries, including Prototype and script.aculo.us.
The files are served with proper caching headers and fully compressed (GZIP), so you don’t have to do it yourself.
In Dion’s words:
- Developers won’t have to worry about getting caching setup correctly, as we will do that for you
- If another application uses the same library (much more likely), they there is a much better chance that it will be already caching on the users machine
- The network and bandwidth of the users systems will not be taxed.
You can either use Google’s API loader (see link to docs below), or just use direct URLs. For example the following code block will load in Protoype and script.aculo.us’ effects (ignore the linebreaks!):
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/effects.js"></script>
You can read up on this at the documentation site.
Tweet This Post
Digg This Post
Share on Facebook









Are there any cross-domain browser issues from loading scripts in this way?
@marten: Is this really promoting XSS though? I know that YUI has serving files for sometime now and I have not heard of any XSS problems.
I was wondering if there was ever any plans to have minified versions of the framework? I may have missed some discussion on this before, but I was wondering if there are any plans. I have seen there are some unofficial minified versions, but I was looking for something from the site. Thanks, Jamie
Excellent news; hopefully there will be a packed version in the future.
masterleep: I expect that for example http://noscript.net/ (Firefox Extension) would block this and give stern warnings. Basically any browser with any Anti-XSS protection will block this.
IMHO, this is a bad idea, XSS is nasty shit and if this gets widespread adoption, it will be tougher to detect XSS attempts on the browser-side.
@adam, @jamie r: again the scripts are served gzipped, which compresses about 1:5. why do you want it packed? this only makes it MUCH slower, as the browser has to use slowish JavaScript to unpack, and it makes finding bugs really hard. you can easily do minifying (removing whitespace/comments) if you really need to– but you’ll only get a ~5% advantage (with GZIP enabled), so I highly doubt it’s worth it. a good link to read up on the really important stuff is http://developer.yahoo.com/performance/rules.html
Our RECOMMENDATION still is: serve concatenated, gzipped JavaScript files with proper headers yourself, or, IN CASE YOU CAN’T, use the google-served files above.
@Marten: Many sites serve images and scripts from different domains. If you use extensions that break the internet, it’s really not anyone’s problem, but your own.
@masterleep: no, this should work for everything. one limitation is that it currently doesn’t work for SSL sites (i hear that support for that is coming).
@Thomas I read the link you offered up from yahoo and they say: "Minify JavaScript and CSS".
"Minification is the practice of removing unnecessary characters from code to reduce its size thereby improving load times. When code is minified all comments are removed, as well as unneeded white space characters (space, newline, and tab). In the case of JavaScript, this improves response time performance because the size of the downloaded file is reduced."
This is what I was talking about and I am not sure how this affects the browser with minification? That was all I was asking was if you were going to minimize the .js files. Minifying does not cause the browser to do ANY extra work.
So your quote "again the scripts are served gzipped, which compresses about 1:5. why do you want it packed? this only makes it MUCH slower, as the browser has to use slowish JavaScript to unpack, and it makes finding bugs really hard." is not relevant to my question. My question was are going to have minified files to have downloaded. Many other frameworks: YUI, jQuery, and MooTools offer up a minimized version of the files. I understand where it might be more difficult to troubleshoot, but it is not uncommon. Even with the Google Served Libraries, mootools and jquery have minimized versions. Google names them uncompressed, but they are minimized versions.
I did not ask for a compact version, I asked about a minified version.
I agree with Ashley, this should be promoted more heavily since there are an enormous amount of sites that still don’t get the value of of combining, pre-compressing and caching their JS, not to mention great sites that lack an infrastructure even remotely close to google’s (needless to say).
Great news! Thanks a lot. Hope it works fine with my website.
Oh great ! Thanks a lot for this Site