[Yii2] how to put my custom javascript After jquery

Hi all, i’m trying to use some javascript component into my application.

But i don’t know how to put them after the jquery.js

I load them in my AssetBundle class:

class CropScaleAsset extends AssetBundle {


  public $sourcePath = '@vendor';

  public $js = [



  public $css = [




 public $jsOptions = array(

    //'position' => View::POS_HEAD // too high

    //'position' => View::POS_READY // in the html disappear the jquery.jrac.js declaration

    //'position' => View::POS_LOAD // disappear the jquery.jrac.js

     'position' => View::POS_END // appear in the bottom of my page, but jquery is more down again



And this is my Widget

class CropScale extends Widget{

    public $message;


    public function init()




        $view = $this->getView();


        $content = " 

                        $(document).ready(function() {

                         alert('DOM loaded'); 



        $this->message = Html::script($content,['type'=>'text/javascript']) ;


        return $this->message;




    public function run()


        return $this->message;





As you see i try the $jsOptions reading in some forum but i don’t solve.

Can someone help me?

Thank’s alot.


i continue to study yii2 and i find the ‘depends’ property in the AssetBundle.php. After some test i solve a part of my problem (or i think so) as this:

    public $depends = [



now my problem is that if a create a simple script on a page with a simple


i get the error “$ is not defined” because jquery is at the bottom of the page and nod in the head. :(

You should be using registerJs().

Did you solved?

put this at the bottom of your AssetBundle class:

    public $depends = [



and only register your bundle in the views that require it.