The depend property in Assets bundle did not work

I initialled a project from Yii2 advanced template, and read Assets.

Then I edited backend\assets\AppAsset with commenting the code

public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ];

It expect the page do not load yii.js and bootstrap.css assets according the doc describing.

Howerver, it did, why?

It will do this whenever yii.js and bootstrap.css is needed, i.e. when you use a form or a Bootstrap widget.

In order to turn them off, you will need to configure the AssetManager (in web.php) like this:

        'assetManager' => [
        ...
        'bundles' => [
            'yii\bootstrap\BootstrapAsset' => false,
            'yii\web\YiiAsset' => false,
        ]
    ],

But what is the depend property purpose?

To make sure that whenever that asset is loaded, the other assets are loaded before it. :wink:

It is a little bit ambiguity.:grinning:

1 Like

Well, it ‘depends’ (sorry about the pun).

If you read it like this, it will make sense:
“The asset (the one you’re looking at) depends on the following other assets”.

Thanks, I got it.:smile: