Yii2 - Include JS Script Only For Specific View

yii2

Solution

You should simply register this js file in your view, e.g. :

$this->registerJsFile('@web/js/specific.js');

Read more : http://www.yiiframework.com/doc-2.0/guide-output-client-scripts.html#registering-scripts

Problem

I want to include my js script `specific.js` for a specific view having action id `specific-action-id`. I don't want the `specific.js` to be included in every page. For including a js script for the whole site I normally have to edit `AppAsset.php`. For this purpose, what should I do?

Original source