$.ready() before closing body

前端 未结 3 1948
终归单人心
终归单人心 2021-02-14 13:21

This is not a real coding question, more of a real-world statement.

I have previously noted that DOMReady events are slow, very slow. So, I noticed while br

3条回答
  •  我寻月下人不归
    2021-02-14 14:06

    Actually, placing a function call before tag makes it pointless to use jQuery's ready(). Just put native JS-wrapper function call that contains calls of all other functions that should be called on document ready.

    In general, it's a working (though somewhat littering HTML code and therefore unacceptable for perfectionists) alternative for situations when author does not need/want to use jQuery at all. In such situations though, I would prefer to use native DOMContentLoaded event handler that is supported by most of browsers including IE9+ (for IE8- we can use window.load() as an acceptable fallback).

提交回复
热议问题