Yii2 - How to include external js file in file at last position

I have a question how to include js file in last position after including jquery file. beacuse, what's the problem now is my js-load, and after that the jQuery file is loaded. as of now, I added a file like:

use frontend\assets\AppAsset;

AppAsset::register($this);
$this->registerJsFile('@frontend_base/web/js/sendverification.js'); 

so this will add the js file, but not the last. so how can i achieve this?

+4
source share
3 answers

In fact, you can make your script jQuery dependent. This is the only real way without applying fancy inclusion features to provide this:

$this->registerJsFile('@frontend_base/web/js/sendverification.js', ['depends' => 'yii\web\JqueryAsset'])

POS_, , JS , .

: http://www.yiiframework.com/doc-2.0/yii-web-view.html#registerJsFile()-detail

+2

Js Js

$this->registerJsFile('@frontend_base/web/js/sendverification.js',['position' => \yii\web\View::POS_END]); 
+1

- AssetBundles. - :

class SendverificationAsset extends AssetBundle {
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $js = [
        'js/sendverification.js'
    ];
    public $depends = [
        'yii\web\JqueryAsset'
    ];
}

:

use frontend\assets\AppAsset;
use frontend\assets\SendverificationAsset;

AppAsset::register($this);
SendverificationAsset::register($this);

, SendverificationAsset Javascript / CSS JQuery.

AssetBundles , / .

0

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


All Articles