Early appendChild hell in top 3 browsers

I am trying to lazily load javascripts, but I cannot get it to work reliably. My pages load pretty quickly, and I want to save them that way, so I'm not going to use a timeout to delay loading. Besides document.readyState, how can I guarantee that the DOM is really ready for modification?

Method I:

  • readyState poll

  • createElement script

  • src = url

  • appendElement to head

Results:

IE8: always interrupts

FF3: loads the first time, interrupts each other

Chrome: loads the first time, interrupts each other

Method II: ( lazyload included in the header)

  • Download with lazyload

Results:

IE8: always interrupts

FF3: works

Chrome: loads the first time, interrupts each other

+3
2

<script> </body>, DOM, , .. -, <script>, .

, , , , , DOM, (jQuery): http://github.com/jquery/jquery/blob/master/src/core.js#L393

+2

Javascript - , . , jquery, , , $(document).ready(). dojo, , addOnLoad. ... - , : JS, ! -)

+1

Source: https://habr.com/ru/post/1757556/


All Articles