I have a page which has document.body.onload=function(){...} but this is suffering delays because the document also contains external <img> tags etc; onload seems to be only getting fired after these external sites have delivered some kind of response.
I put the code in onload because I thought the DOM tree wasn’t fully available until then (e.g. document.getElementById(x) might return null if it is called too soon).
Is there an event which triggers after everything in the DOM is accessible, but before everything has been loaded?
You can just place your
<script>tag at the end of the body since the html is parsed in sequence.Additionally, you could look at
jquery‘s document.ready. Even if you don’t want to use jquery, you can have a look at how they handle it.readydoes exactly what you’re asking for.