I donβt know if there is an official way to do this (maybe not as if the specification of the options object was too complicated), however there is another simpler way compared to the accepted answer, which does not require you to create another AssetBundle .
All you have to do is create another array, for example:
public $head_js = [ "path/to/src.js" ];
Then override the registerAssetFiles function as follows:
public function registerAssetFiles($view) { foreach($this->head_js as $js) { $options = []; $options["position"] = \yii\web\View::POS_HEAD; $url = Url::to($this->baseUrl . "/" . $js); $view->registerJsFile($url, $options); } parent::registerAssetFiles($view); }
source share