title: Yii2: how to use Asset Bundle for scripts
body: <p>I have read the docs, but can't make out how to do that for example I have a small script in file <code>index.php</code> in view folder <code>medicine-issue-entry</code> like:</p>
  
  <pre><code>&lt;?php
  $js = 'function refresh() {
       $.pjax.reload({container:"#medicine_request_entry"});
       setTimeout(refresh, 60000); // restart the function every 5 seconds
   }
   refresh();';
   $this-&gt;registerJs($js, $this::POS_READY);
  ?&gt;
  </code></pre>
  
  <p>Where I can put this code in a separate file and how to include that in the relevant file.
  A detailed process will be greatly appreciated.
  Thanks.</p>
  
  <p>Ok I am using the basic template.
  In <code>AppAsset.php</code> I have included like</p>
  
  <pre><code>public $js = [
  
          'js/autorefresh.js'
      ];
  </code></pre>
  
  <p>and created a folder <code>js</code> in <code>web folder</code> and created a new file autorefresh.js with the following code:</p>
  
  <pre><code>function refresh() {
           $.pjax.reload({container:"#medicine_request_entry"});
           setTimeout(refresh, 60000); // restart the function every 5 seconds
       }
       refresh();
  </code></pre>
  
  <p>and in my <code>index.php</code> I have added the line</p>
  
  <pre><code>namespace app\assets;
  use app\assets\AppAsset;
  AppAsset::register($this);
  </code></pre>
  
  <p>But the same is not working, am I still missing something? As when I include the code in the file with <code>registerJs</code> it is working fine.</p>
  
  <p><strong>Note:</strong> on viewing the page source the file is correctly published and clicking on the link it show the script, but the code is not working.</p>