Yii2 add javascript to view file

When working with the yii2 framework we can dynamically register frontend scripts to the view file. This can be applied using the following hook

registerJsFile()

We can append any external or internal javascript file url to the custom yii2 view file 

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

where @web represent the public root folder usuallt public_html folder for the yii2 application

We can also append depends parameter which is optional in case if we want to use the loaded javascript file to be dependent onother javascript file

yii2,javascript