Today, Google
announced the opening of the
Google AJAX Libraries API . What is it and why do I need to briefly explain.
First, it is the repository of all versions of the following libraries:
- jQuery
- Dojo
- MooTools
- script.aculo.us
- prototype
This means you can get any version of the library immediately in the page code using a special request (more on that later). It also means that you don’t have to store all these heaps of files on your server and change the file with the release of new versions. And yes, the compressed versions are also stored on the Google server.
Secondly, the Google server infrastructure is working well enough and the servers can provide good speed for issuing files. If someone has already downloaded this file from the Google server, it may already be in the cache. Developers do not have to worry about compression and cache, Google will do it.
Thirdly, it all works as simple as possible. To get the library you need, you can use two methods. The easiest is to make a request through
')
For example, we need to get prototype version 1.6.0.2:
<script src = "http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.min.js"> </ script>
The second way is to load the library through the google.load method from
Loader's Google AJAX API.Example for jQuery:
<script src = "http://www.google.com/jsapi"> </ script>
<script>
// load jQuery
google.load ("jquery", "1");
// when the page is loaded, we call the jQuery method
// search through google :)
google.setOnLoadCallback (function () {
$ .getJSON ("http://ajax.googleapis.com/ajax/services/search/web?q=google&;v=1.0&;callback=?",
// the request is complete, we get the data
function (data) {
if (data.responseDate.results &&
data.responseDate.results.length> 0) {
renderResults (data.responseDate.results);
}
});
});
</ script>
That's all :)
Another interesting thing is downloading the latest version of the library. When we specify a file version, you can indicate that we want to download the latest version. For example, if we specify the version “1” for jQuery, we will load version 1.2.6. For the rest of the libraries as well. You can specify version branches. That is, if we specify version 1.2, then we will download 1.2.6. But when version 1.3.x comes out, it will not be loaded.
By default, the compressed version of the library is loaded, and to load a regular version, you need to specify in the query string what we want to load. for example
<script src = "http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"> </ script>
This is if we use the URL for the request. And if we use the google.load method, then we need to specify the additional parameter {uncompressed: false} in the function
Additional links:
Official pageDocumentationvia
Ajaxian