How soon will jQuery(document).ready be called?

后端 未结 3 1044
情深已故
情深已故 2020-12-10 16:35

If a third party javascript file hangs and takes a while to load, will

jQuery(document).ready(function() {}) 

have to wait for that to

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 17:35

    The 3rd party js file may be blocking, especially if it's in the head tag. Try putting it just before the closing tag.

    I think the first answer is incorrect - document.ready doesn't mean that all content has to be loaded, it means that the dom is complete. Otherwise, jquery methods run inside this wouldn't run until all images (for example) were loaded, which is not true.

    Edit

    It looks like the behaviour is different for scripts, but can be browser specific. There is a good explanation here:

    JavaScript: DOM load events, execution sequence, and $(document).ready()

提交回复
热议问题