Js file duplicatedly included in ajax response generated using render() method

Some widgets in the ajax response have some js file included such as jquery-ui which is included already in the main caller page, how to avoid this?

You should not use ‘render’ in a ajax response, because render includes the whole html-layout too.

Use renderPartial in the controllers action:





if (Yii::app()->request->isAjaxRequest)

  $this->renderPartial('view'....);

else

  $this->render('view'....);



Take a look a this wiki article: Ajax with renderPartial

Thanks Joblo, Do I have to use renderPartial? I have set CController::layout to false so that render() won’t include the layout file anymore, but clientscripts still involved.

When using renderPartial you can decide to set $processOutput=false or true, means to render the clientscripts to output or not.

Default is false, so the clientscripts are not rendered.

From my tests clientscripts still rendered which brought by the widgets such as

<?php


$this->beginWidget('zii.widgets.jui.CJuiDialog', array(


	'id' => 'mydialog',


	'options' => array(


		'title' => $text,


		'autoOpen' => true,


	),


));


?>

regardless $processOutput true or false