I have A.php view file in /views/A/ folder.
And I have A.js js file in /views/A/ folder
Please help me register js file in view file.
As I unde
If you register a js file by:
$this->registerJsFile("@web/js/all.js");
This will work but you will not be able to use jQuery. Because this file all.js is loaded before jQuery. To load after jQuery we make it depend it on 'yii\web\YiiAsset' or on \yii\web\JqueryAsset . So it will be loaded after jQuery.js. Example:
$this->registerJsFile("@web/js/all.js",[
'depends' => [
\yii\web\JqueryAsset::className()
]
]);
So What is difference between \yii\web\JqueryAsset and \yii\web\YiiAsset?
In jQueryAsset the js file will load after jQuery.js and in YiiAsset the js file will load after yii.js file.
If you want to create your own custom Asset Bundle: