Yii and Google AJAX APIs

I'd like to use JQuery in the development, but to save traffic I'd like to use Google APIs (http://code.google.com/apis/ajaxlibs/) instead of serving JQuery files locally. How can I register and use all JQuery-dependent widgets, but not serve jquery.js file locally?

Currently you can extend CClientScript and override renderCoreScript() to achieve this.



<?php


public function renderCoreScript($name)


{


   if($name==='jquery')


      return 'URL for google jquery';


   return parent::renderCoreScript($name);


}


After extending, you need to set it in app config as:



return array(


   'components'=>array(


       'clientScript'=>'path.to.myclientscriptclass',


   ),


);


We are considering adding more features to CClientScript, such as the one you just requested, and perhaps compression, and so on.

In this case there’s no url to google’s jquery file. Instead, there’s url to google’s loader, which requires a separate step - add a javascript call:

google.load("jquery", "1");

So I can't just override renderCoreScript. I'll need to manually add the code above to my web pages, so the whole solution becomes quite messy because there's no clear link anymore between overridden renderCoreScript and google.load call.

I didn't notice that. You can call registerScript in renderCoreScript to achieve this.

Quote

In this case there's no url to google's jquery file. ...
google.load("jquery", "1");

All the libraries have their respective URLs to the compressed source files. See http://code.google.c…/documentation/