title: Why can I not call these JQuery/Javascript Functions in an external script file?
body: <p>I am writing a lot of JQuery code in a page and have decided to move some of the functions out to a separate file.  So, file #1 has nothing but function definitions:</p>
  
  <pre><code>function doSomething() { ... } 
  
  function doSomethingElse() { ... }
  </code></pre>
  
  <p>In the main page, I have placed my JQuery at the end of the file - following the optimization techniques found in Zakas' book "High Performance Javascript".</p>
  
  <p>So, at the very end of the file (but before the closing body tag) I have:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/scripts/MyFunctions.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      doSomething();
      doSomethingElse();
   ....
  &lt;/script&gt;
  </code></pre>
  
  <p>Note that the final Javascript scripts are loaded - and run - after the page is loaded and the DOM declared.  However, I get an error every time that says <strong>'doSomething' is undefined.</strong></p>
  
  <p>This works without problem if the functions are included in the main script.  It is only when I pull them outside that I get this error.  Now, my guess is that the first file hasn't being fully loaded/compiled when the second one makes its calls.  But it seems to me that the last script (essentially acting in the "Ready" role) should be the one compiled last.  When I look at JQuery and other JS files, they start with anonymous functions rather than just launching right in to function definitions so clearly there is something else going on.</p>
  
  <p>Note that I don't <em>think</em> it is a problem loading/finding the file: I've tried various paths to ensure that the path is correct and that hasn't fixed the issue.</p>
  
  <p>Does anyone have a clue why my functions aren't being found?</p>
  
  <p>Update: If I take the file contents exactly as they are found and put it into the first script tag rather than loading it from the file, this works fine.  But I have checked the script file name repeatedly and it is correct.  So it is something about the process of loading it from an external file.</p>
  
  <p>UPDATE: Solved.  I ran it through FireBug as keegan and dskrepps suggested and it jumped right out at me.  I had an ASP.NET variable that I was placing in the scripts but, of course, ASP.NET isn't parsing the file or replacing variables.  When Javascript saw these replaceable values, it was dying on a parse error that wasn't reported.  So - the file was NOT being loaded and it isn't a Javascript function call issue at all.  Instead, it was an error between the keyboard and the seat. ;-)</p>
  
  <p>Thanks to everyone who helped!</p>