title: How can I include a script with document.write?
body: <p>We need to add a script to our web application. It basically adds an corporate menu.</p>
  <p>So we've received a script to include in the body of our web application:</p>
  <pre><code>&lt;!-- BEGIN NAVIGATION --&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;https://intranet.local/?getCorporateJsMenu&quot;&gt;&lt;/script&gt;
  &lt;!-- END NAVIGATION --&gt;
  </code></pre>
  <p>And the content of <a href="https://intranet.local/?getCorporateJsMenu" rel="nofollow noreferrer">https://intranet.local/?getCorporateJsMenu</a> basically looks like this:</p>
  <pre><code>document.write('&lt;script type=&quot;text/javascript&quot; src=&quot;...&quot;&gt;&lt;/script&gt;');
  //....
  document.write('&lt;div&gt;');
  document.write('&lt;ul&gt;');
  //...
  document.write('&lt;li&gt;&lt;a href=&quot;...&quot;&gt;...&lt;/a&gt;&lt;/li&gt;');
  //...
  document.write('&lt;/ul&gt;');
  document.write('&lt;/div&gt;');
  </code></pre>
  <p>After having placed the <code>&lt;!--NAVIGATION--&gt;&lt;script...</code> directly into the HTML body, we were experiencing severe page load performance problems.</p>
  <p>So our idea was to add the menu with JavaScript, when everything has already been loaded with something like this:</p>
  <pre><code>var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://intranet.local/?getCorporateJsMenu';
  var domparent = jQuery('#header').get();
  domparent[0].appendChild(script);
  </code></pre>
  <p><strong>With <a href="https://en.wikipedia.org/wiki/Firebug_%28software%29" rel="nofollow noreferrer">Firebug</a> we see, that the script element has been added to the HTML content and the script has been loaded from the network, but somehow the document.write of the loaded script doesn't get executed. Why?</strong></p>
  <hr />
  <p>We cannot modify the contents of <a href="https://intranet.local/?getCorporateJsMenu" rel="nofollow noreferrer">https://intranet.local/?getCorporateJsMenu</a> since it comes from third party.</p>