Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of the script.aculo.us user interface JavaScript library, a member of the Prototype core team and a Ruby on Rails core alumnus. You're using my work every day, even if you're not aware of it (sounds creepy, I know!). Need JS foo? Hire me.

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.

Post to Twitter Tweet This Post Post to Digg Digg This Post Post to Facebook Share on Facebook

10 comments »

JavaScript Rocks! Peformance ebook
Do you run a web site or web application? Do your users a favor, and grab our ebook on JavaScript performance. Profit from our knowledge gathered in over 15 years of working with the Web and JavaScript and make your sites ultra-fast and your users ultra-happy.

10 Comments on “Google-served JavaScript libraries”

  1. 1 masterleep said at 4:29 pm on May 27th, 2008:

    Are there any cross-domain browser issues from loading scripts in this way?

  2. 2 Jamie R said at 4:29 pm on May 27th, 2008:

    @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.

  3. 3 Jamie R said at 4:29 pm on May 27th, 2008:

    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

  4. 4 Adam said at 4:29 pm on May 27th, 2008:

    Excellent news; hopefully there will be a packed version in the future.

  5. 5 Marten said at 4:29 pm on May 27th, 2008:

    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.

  6. 6 Thomas Fuchs said at 4:29 pm on May 27th, 2008:

    @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).

  7. 7 Jamie R said at 4:29 pm on May 27th, 2008:

    @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.

  8. 8 Frederick Townes said at 4:29 pm on May 27th, 2008:

    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).

  9. 9 Sandra said at 4:29 pm on May 27th, 2008:

    Great news! Thanks a lot. Hope it works fine with my website.

  10. 10 k-ny said at 4:29 pm on May 27th, 2008:

    Oh great ! Thanks a lot for this Site :)