I’m making a widget for a Yii application. The main layout view registers all the common script files such as jQuery and jQueryUI. In my widget I want to use a jQueryUI plugin that relies on jQueryUI already being loaded.
I know I can specify where on the page the script is included, but it seems a bit hit and miss to simply include it at the “end” – what if I have other script that I need to load after that plugin? How do I ensure they’re loaded in the right order – anyone got any ideas?
You can use the dependency feature in Yii script packages. I was having similar problem before.
For example you have script packages config like below,
In sample above,
package2requires (depends)package1andpackage3requirespackage2. Let’s say in your case, a widget usespackage2, and the other script usespackage3. Even if you don’t render the widget, if you useYii::app()->clientScript->registerPackage('package3');, it will automatically install thepackage2which then install thepackage1beforepackage2(or won’t install if thepackage1is already required by some scripts before.).