I'm building an emoji picker and the most demanding task is creating ~1500 DOM elements for each emoji which blocks/makes the page unresponsive for about 500-700ms.
I've debugged this and it seems like the creation of DOM elements is what blocks the rest of JS execution:
function load_emojis(arr){
var $emojis = [];
# arr.length = 1500
_.each(arr, function(){
$emojis.push($('<span/>').append($('<img/>')));
});
$('.emojis').html($emojis);
}
is there a way to execute this whole thing asynchronously/in another thread so it doesn't block the JS following it?
I've tried to put it inside setTimeout but that still seems to be executed in the same thread thus still blocking JS execution.