Start using Google CDN for your javasripts !

Status
Not open for further replies.

litewarez

Active Member
1,367
2008
1
0
For those who are using Jquery/MooTools/script.aculo.us etc, you can use google to load your frameworks with ease, the benifits of using the CDN is
  • Less bandwidth
  • Faster loading
  • 1 Javascript call

What the CDN Does is provide you with a framework you can use to load all your other framworks. examples below

If you wanted to use just jQuery you can use the following

PHP:
/*Firstly pull the main library from Google, this is al you need to load*/
<script src="http://www.google.com/jsapi"></script>

/*Then you can tell the library what frameworks you wish to use*/
google.load("jquery", "1");
/*The second parameter is the version you wish to use. by setting to 1, this will load the latest version in the 1.x range*/

/* Google offer a neat callback function to load when document is ready*/
google.setOnLoadCallback(myCallBackFunc());

/*No heres an example callback function*/
function myCallBackFunc(){
   console.log("myCallBackFunc as been called!");
   
   /*Heres just an example usage from jQuery*/
   $.getJSON(
      "http://ajax.googleapis.com/ajax/services/search/web?q=google&v=1.0&callback=?",
      // on search completion, process the results
      function (data) {
        if (data.responseData.results &&
            data.responseData.results.length > 0) {
          var results = data.responseData.results;
          
          for (var i=0; i < results.length; i++) {
            // Display each result however you wish
            alert(results[i].titleNoFormatting);
          }    
        }
   });
}

if your user has already used a site that uses the CDN, the libary will already have been loaded into there catch meaning it wont even need to load again,

also your versions will always be updated aswell

Heres some links
http://code.google.com/apis/ajaxlibs/
http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery
http://code.google.com/apis/ajax/playground/?exp=libraries#jquery

I hope you can see that using the was will be much faster for your users and less bandwidth for yourself :P

peace
 
5 comments
yea its not about keeping it short.. its about having 11 different frameworks avaialable at ease and speed... also by using the google object you have the functionality of intergreating the google services with ease such as youtube embeding/google earth maps with or without maps browser plugin and you also have a range of services outside of the google structure :)

Here are just some of the API's you can use with the one JavaScript include
Code:
Google Maps
Google AJAX Search
Google AJAX Feeds
Google AJAX Language
Google Data API's
Google Earth
Google Visualization
Google Friend Connect

Not to mention al the Javascript Framw Works you can call
Code:
jQuery
jQuery UI
Prototype
script.aculo.us
MooTools
Dojo
SWFObject
Yahoo! User Interface Library (YUI)
Ext Core
Chrome Frame
I think i would be better if people started to use the CDN for ease.
 
Status
Not open for further replies.
Back
Top