http://ajaxian.com/archives/announcing-ajax-libraries-api-speed-up-your-ajax-apps-with-googles-infrastructure

http://code.google.com/apis/ajaxlibs/

I just got to announce the Google AJAX Libraries API which exists to
make Ajax applications that use popular frameworks such as Prototype,
Script.aculo.us, jQuery, Dojo, and MooTools faster and easier for
developers.

Whenever I wrote an application that uses one of these frameworks, I
would picture a user accessing my application, having 33 copies of
prototype.js, and yet downloading yet another one from my site. It
would make me squirm. What a waste!

At the same time, I was reading research from Steve Souders and others
in the performance space that showed just how badly we are doing at
providing these libraries. As developers we should setup the caching
correctly so we only send that file down when absolutely necessary. We
should also gzip the files to browsers that accept them. Oh, and we
should probably use a minified version to get that little bit more out
of the system. We should also follow the practice of versioning the
files nicely. Instead, we find a lot of jquery.js files with no
version, that often have little tweaks added to the end of the fils,
and caching is not setup well at all so the file keeps getting sent
down for no reason.

When I joined Google I realised that we could help out here. What if
we hosted these files? Everyone would see some instant benefits:

    * Caching can be done correctly, and once, by us... and developers
have to do nothing
    * Gzip works
    * We can serve minified versions
    * The files are hosted by Google which has a distributed CDN at
various points around the world, so the files are "close" to the user
    * The servers are fast
    * By using the same URLs, if a critical mass of applications use
the Google infrastructure, when someone comes to your application the
file may already be loaded!
    * A subtle performance (and security) issue revolves around the
headers that you send up and down. Since you are using a special
domain (NOTE: not google.com!), no cookies or other verbose headers
will be sent up, saving precious bytes.

This is why we have released the AJAX Libraries API. We sat down with
a few of the popular open source frameworks and they were all excited
about the idea, so we got to work with them, and now you have access
to their great work from our servers.

Details of what we are launching

You can access the libraries in two ways, and either way we take the
pain out of hosting the libraries, correctly setting cache headers,
staying up to date with the most recent bug fixes, etc.

The first way to access the scripts is simply be using a standard
<script src=".."> tag that points to the correct place.

For example, to load Prototype version 1.6.0.2 you would place the
following in your HTML:
PLAIN TEXT
HTML:

   1.

   2.
      <script 
src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js";></script>
   3.


The second way to access the scripts is via the Google AJAX API
Loader's google.load() method.

Here is an example using that technique to load and use jQuery for a
simple search mashup:
PLAIN TEXT
HTML:

   1.

   2.
      <script src="http://www.google.com/jsapi";></script>
   3.
      <script>
   4.
        // Load jQuery
   5.
        google.load("jquery", "1");
   6.

   7.
        // on page load complete, fire off a jQuery json-p query
   8.
        // against Google web search
   9.
        google.setOnLoadCallback(function() {
  10.
          
$.getJSON("http://ajax.googleapis.com/ajax/services/search/web?q=google&;v=1.0&;callback=?";,
  11.

  12.
            // on search completion, process the results
  13.
            function (data) {
  14.
              if (data.responseDate.results &&
  15.
                  data.responseDate.results.length>0) {
  16.
                renderResults(data.responseDate.results);
  17.
              }
  18.
            });
  19.
          });
  20.
      </script>
  21.


You will notice that the version used was just "1". This is a smart
versioning feature that allows your application to specify a desired
version with as much precision as it needs. By dropping version
fields, you end up wild carding a field. For instance, consider a set
of versions: 1.9.1, 1.8.4, 1.8.2.

Specifying a version of "1.8.2" will select the obvious version. This
is because a fully specified version was used. Specifying a version of
"1.8" would select version 1.8.4 since this is the highest versioned
release in the 1.8 branch. For much the same reason, a request for "1"
will end up loading version 1.9.1.

Note, these versioning semantics work the same way when using
google.load and when using direct script urls.

By default, the JavaScript that gets sent back by the loader will be
minified, if there is a version supported. Thus, for the example above
we would return the minified version of jQuery. If you specifically
want the raw JavaScript itself, you can add the "uncompressed"
parameter like so:
PLAIN TEXT
JAVASCRIPT:

   1.

   2.
      google.load("jquery", "1.2", {uncompressed:true});
   3.


Today we are starting with the current versions of the library, but
moving forward we will be archiving all versions from now onwards so
you can be sure they are available.

For a full listing of the currently supported libraries, see the documentation.

Here I am, talking about what we are doing in two short slides:

-- 
Scott Wickham

Reply via email to