title: Yii - External JS files Inlclude , registerScriptFile and publish
body: <p>I am using YII framework for my web application . I have a question on registering external Java script file.</p>
  
  <p>Could some one please help me ?</p>
  
  <ol>
  <li>What is the best location to copy Java script file ( which folder )</li>
  <li><p>I do see there are two ways to register that external Java script
  file</p>
  
  <p><strong>First approach</strong></p>
  
  <pre><code> $baseUrl = Yii::app()-&gt;baseUrl; 
   $cs = Yii::app()-&gt;getClientScript();
   $cs-&gt;registerScriptFile($baseUrl.'/js/yourscript.js'); 
  </code></pre>
  
  <p><strong>Second approch</strong>  </p>
  
  <pre><code> $cs=Yii::app()-&gt;getClientScript();
   $cs-&gt;registerScriptFile(Yii::app()-&gt;getAssetManager()-&gt;publish('path/to/js'));
   $cs-&gt;registerScript('id', 'your js here');
  </code></pre></li>
  </ol>
  
  <p>In the first approach I am directly registering with  registerScriptFile and passing the java script file </p>
  
  <p>In the second approach I am registering and publishing the script . That means it copies to assets folders. ( Please correct me If I am wrong )
  and then what does the last step does, What is <code>id</code> and again <code>java script file</code> . (<code>$cs-&gt;registerScript('id', 'your js here');</code>)</p>
  
  <p>In my case I am accessing it from one of the views , so in the second approach since it gets published to the asset folder  , if 10 clients calls the file does it published 10 times ( since I am accessing it from the  view file )</p>
  
  <p>I am bit confused .</p>
  
  <p>Thanks for your answer</p>
  
  <p>Regards</p>
  
  <p>Kiran</p>