JavaScript onload or init or ...?
<p>What is the best practice for loading an external .js file into an .html file? (no inline calls e.g., <code>&lt;body onload="...</code>)</p>

<p>I have a basic HTML page where I'd like to load an external .js file. When I have the code in a script tag at the bottom of my HTML page everything works as it should.</p>

<p>However if I cut the js code and paste it into an external .js file and call the file from either the bottom of the <code>&lt;head&gt;</code> tag or place the call to the script just above the closing <code>&lt;/body&gt;</code> tag the script doesn't run.</p>

<p>Unsuccessful, but I've also tried wrapping the code in the external .js file in:</p>

<pre><code>function init() {
    // Put your code here
}
window.onload = init;
</code></pre>
