Are you aware of the script attribute “defer?” If you have and external file, you may use:
- <script src=”the external file.js” defer=”defer”></script>
If you use a script defer at the top of the file with other script requests, that JavaScript will not be processed until the page has finished parsing. This can be an interesting alternative to placing your JavaScript in footers (as many people seem to do). This assures that all objects exist at the time that the JavaScript is executed …
The defer attribute is supported by all major browsers.
Consider using scripts with external files in the header with defer more frequently!