YII2 calls jquery-ui code before loading bootstrap.js

Here is my asset code.

public $js = [ 'js/jquery-ui.min.js', 'js/app.min.js', ]; 

I have some widgets used in a view file ... and here is the order of the js files. I want to call jquery-ui.js before bootstrap.js .. How to do this?

enter image description here

+5
source share
1 answer

Placing a jQuery UI after Bootstrap makes no sense, as they are independent of each other at all. But to include a package before another, you should add a dependency on the associated package.

For a custom asset package, you can simply write this:

 $depends = [ // Write classes of dependent asset bundles here, for example: 'yii\jui\JuiAsset', ]; 

But since Bootstrap is a built-in asset, you cannot change it. Instead, you can install it globally through the Asset Manager configuration:

 return [ // ... 'components' => [ 'assetManager' => [ 'bundles' => [ 'yii\bootstrap\BootstrapAsset' => [ 'depends' => [ 'yii\jui\JuiAsset', ]; ], ], ], ], ]; 

Or just install the dependency in one specific place before rendering:

 Yii::$app->assetManager->bundles['yii\bootstrap\BootstrapAsset'] = [ 'depends' => [ 'yii\jui\JuiAsset', ]; ], 

Official documents:

+3
source

Source: https://habr.com/ru/post/1233669/


All Articles