title: Which is the better way of injecting javascript into my application?
body: <p>Based on user's preferences I inject into my application a jason_encoded(translation array) which is later converted to javascript object and used by the application. Which, in your opinion, is the better way to do it?</p>
  
  <p>Solution 1:</p>
  
  <pre><code>&lt;head&gt;
     &lt;script type="text/javascript" src="lang.php"&gt;&lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>Solution 2 (code is executed inside index.php): </p>
  
  <pre><code>&lt;head&gt;
         &lt;?php
             require_once(database_connect.php);
             //Prepare $myDictionary...
  
             $dictionary = json_encode($myDictionary);
             echo ("
                &lt;script type='text/javascript'&gt;
                   var dictionary=". $dictionary .";
                &lt;/script&gt;
             ");
  
             require_once(database_close.php);
         ?&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>I'am currently using the first solution, because I can cache the results, but I wan't to know if putting all that php code (including require/include functions) inside index.php is good or bad idea. Thanks for any suggestions.</p>