You can use the dependency function in Yii script packages . I had a similar problem before .
For example, you have script packages, as shown below,
'clientScript' => array( 'packages' => array( 'package1' => array( 'basePath' => 'path.to.package1', 'js' => array( 'package1.js', ), 'css' => array( 'package1.css' ), ), 'package2' => array( 'basePath' => 'path.to.package2', 'js' => array( 'package2.js', ), 'css' => array( 'package2.css' ), 'depends' => array( 'package1', ) ), 'package3' => array( 'basePath' => 'path.to.package3', 'js' => array( 'package3.js', ), 'css' => array( 'package3.css' ), 'depends' => array( 'package2', ) ), ) )
In the above example, package2 requires (depends) package1 and package3 requires package2 . Say, in your case, the widget uses package2 , and another script uses package3 . Even if you do not render the widget, if you use Yii::app()->clientScript->registerPackage('package3'); , it will automatically install package2 , which will then install package1 to package2 (or will not install if package1 is already required in some scenarios before.).
source share