JQuery: use function instead of $ (document) .ready

I use the Piety plugin on a website that displays leader profiles. Each profile contains a different number of elements to which Piety applies, and I found that it $(document).readystarts before all these elements have loaded.

My solution so far has been to move Piety from $(document).readyto $(window).load- which works great for most profiles. However, the people at the top of the leaderboard have extremely large profiles, which creates a rather long wait before they $(window).loadstart working and work through all the elements of Piety.

I am wondering if there will be any performance problems if I have to call each pie separately as they load, instead of waiting $(window).loadand letting jQuery do everything all at once.

Sort of..

From:

$(window).load(function(){
   $("span.pie").peity("pie", { ... })
}); 

To:

function loadPie(id){
    $("#"+id).peity("pie", { ... })
}

.. and then loadPie after each item.

+5
source share
1 answer

If profiles are loaded asynchronously after the DOM is ready, then yes, initializing the reliability of each of them after loading them makes sense. $ (window) .load () waits while everything else on the page (associated with the profile or not) is fully loaded.

, , - . , / , ( window.load). jsperf ... :)

+1

All Articles