Well, I’ve been scratching my head for a few hours now over configuring CClientScript.
For a project I’m working on, I have many small javascript files for different pages. When all combined, it comes out to about 5kb compressed, so it makes more sense to do what is outlined here (http://www.yiiframework.com/doc/guide/topics.performance) and combine them all into an “all.js” file.
I tried what is outlined in the performance guide, and can’t seem to get it to work. Not only are jQuery and the like being included from the /assets folder rather than Google, the other files aren’t mapping to /js/all.js.
Here’s what my config looks like:
'components'=>array(
...
'scriptMap'=>array(
'jquery.js'=>false,
'jquery.min.js'=>false,
'jquery.ajaxqueue.js'=>false,
'jquery.metadata.js'=>false,
'taskInterface.js'=>'/js/all.js',
'ajaxGridButtonAction.js'=>'/js/all.js',
'gridViewTooltip.js'=>'/js/all.js',
'jquery.tools.min.js'=>'/js/all.js',
'project.js'=>'/js/all.js',
'projectView.js'=>'/js/all.js',
),
...
),
and here’s what I have at the top of my layouts:
<?php echo CGoogleApi::init(); ?>
<?php echo CHtml::script(
CGoogleApi::load('jquery','1.4.2') . "\n" .
CGoogleApi::load('jquery.ajaxqueue.js') . "\n" .
CGoogleApi::load('jquery.metadata.js') . "\n" .
CGoogleApi::load("jqueryui", "1.8.2")
); ?>
I’m using some widgets, which use things like:
if($this->jTools===null) { $jsfile=dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'jquery.tools.min.js';
$this->jTools=Yii::app()->getAssetManager()->publish($jsfile);
}
$cs->registerScriptFile($this->jTools);
and it seems as if those at least should be remapped by CClientScript, but they don’t appear to be.
In some of my views, I’m also using things such as:
echo CHtml::scriptFile(Yii::app()->request->baseUrl.'/js/jquery.tools.min.js');
echo CHtml::scriptFile(Yii::app()->request->baseUrl.'/js/gridViewTooltip.js');
to require my javascript files; I’m not sure if that would work with CClientScript remapping them to /js/all.js. Still, if I use something CClientScript to register a file in the place of CHtml::scriptFile(…), nothing is remapped to /js/all.js.
I need the remapping, because while things work fine on my local machine, the application running live on our server is taking about 400-500 ms to load each javascript file from assets, adding up to quite a few seconds for each page load. If they’re combined, and being loaded from Google, my hope is that the page load times will be slightly more manageable.
One other thing - I’m using quite a bit of ajax and $this->renderPartial(‘someView’,array(‘someParams’=>$someParams),true,false); to render pages and views. Could this be upsetting CClientScript’s expected behavior in some way?
Thanks