title: Use JavaScript to prevent a later `<script>` tag from being evaluated?
body: <p>This is a bit of an oddball use case, but I have my reasons:</p>
  
  <p>I'd like to be able to write</p>
  
  <pre><code>&lt;script type="text/javascript" src="first.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="second.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>in my markup and, using the code in <code>first.js</code>, prevent or delay the execution of <code>second.js</code>. Is this possible, in any browser? What if the contents of <code>first.js</code> are inlined? (If it helps, assume that the second script tag has an <code>id</code> attribute.)</p>
  
  <p>Since I've gotten a couple of answers that missed what I'm getting at, I should clarify:</p>
  
  <ol>
  <li>The solution must be entirely within <code>first.js</code>. Anything that require changes to the original HTML of the page, or to <code>second.js</code>, is not acceptable.</li>
  <li>It <em>is</em> acceptable to load <code>second.js</code> via Ajax and execute it using <code>eval</code>. That's the easy part. The hard part is preventing the immediate execution of <code>second.js</code>.</li>
  <li>Assume that you <strong>don't know</strong> what's in <code>second.js</code>. So, you can't just replace each global function called by <code>second.js</code> with a no-op function. (Plus, this would almost certainly lead to errors.)</li>
  </ol>
  
  <p>If you know of a solution that works in some browsers but not in others, I'd love to hear it.</p>
  
  <p><strong>Example</strong>: To make this a little more concrete, let's say that the code</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    function func() {
      window.meaningOfLife = 42;
      window.loadSecond();
    };
    setTimeout(func, 10);
  &lt;/script&gt;
  </code></pre>
  
  <p>precedes the two <code>script</code> includes, and that <code>second.js</code> contains the line</p>
  
  <pre><code>if (window.meaningOfLife !== 42) {throw new Error();}
  </code></pre>
  
  <p><code>first.js</code> should be able to prevent this error by delaying <code>second.js</code> from executing until <code>window.loadSecond</code> is run. (Assume the implementation of <code>window.loadSecond</code> is also in <code>first.js</code>.) It is <strong>not</strong> allowed to touch <code>window.meaningOfLife</code>.</p>
  
  <p><strong>Update</strong>: Alohci's answer meets these requirements, but only on the condition that the second script tag comes <em>immediately</em> after the first, with nothing but whitespace in between. If someone could extend his hack to avoid that requirement, without introducing other unwanted consequences, that would be amazing...</p>