Javascript – How to load external javascript file first before using it in BODY onload event


    <script type="text/javascript" src="folder/externaljs.js">

<body onload="someFunctionInExternalJS();">

How do I ensure that externaljs.js is loaded first so that someFunctionInExternalJS() is executed as a result? Thanks!

Best Solution

The external javascript file will load and execute before continuing along and building the DOM, unless it is async (

Any external file that the DOM requires to build (javascript, css primarily) will load as it is being parsed. This is why you will sometimes see javascript at the bottom of the body tag instead of the head.