Quantcast
Channel: Dave Mackintosh
Viewing all articles
Browse latest Browse all 10

Window load vs document ready

$
0
0

I see this issue all the time and perhaps even more worryingly I see the use of setTimeout() in places to defer listeners.

If you don’t need to wait for images/scripts to load use:

(function ($) {
        $(document).ready(function () {
                //Code here
        });
})(jQuery);

If you need to wait for media to load, use this:

(function ($) {
        $(window).load(function () {
                //Code here
        });
})(jQuery);

Simple as that!


Viewing all articles
Browse latest Browse all 10

Trending Articles