How to make the registerJS method code to depend on AppAsset

I have the AppAsset connected to the main js file of the website;It contains some global functions which I use in view registerJS (being executed at the end: POS_END) javascript code.

What I have noticed is, the code in file(AppAsset bundle) is being execute after registerJS’ code. I would like the code from the file to be first executed then registerJS.

How can I make that happen?

My AppAsset.php file in basic app


namespace app\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle


    public $basePath = '@webroot';

    public $baseUrl = '@web';

    public $css = [



    public $js = [



    public $depends = [


        // ...



And in view


$js = <<<JS

    function cb(start, end) {

        // Code




?> // OR


// Include JS or Css Files in view page

$this->registerJsFile('//path-to-js-file.js', ['depends' => [yii\web\JqueryAsset::className()]]);

$this->registerCssFile('//path-to-css-file.css', ['depends' => [yii\web\JqueryAsset::className()]]);


Just try it. it will work like a charm…

Thanks!!! I understand and it is working fine.