Googled: it all comes down to the banal for and $ .attr () loop

Simplified:

Файлы: 1.png 2.png 3.png 4.png ... 10.png (по 250кб скажем каждый) for(var i = 1; i<=10; i++) { now = file_dir + i + '.png'; $('<img>').attr('src', now); } 

So it feels like the browser is hung (mb. When the connection is weak, or say some image is temporarily unavailable for one reason or another). Is it possible to somehow optimize it, more "passively"? (in the background, load, continue to perform other $ .on (); and let us say if it is not available within 10 seconds, then go to the next one) who else can advise what. Thank you in advance!

    1 answer 1

    So hanging timers waiting for download will not make it easier for the browser to work. can your loop, some kind of wrapper is missing? therefore the browser is hung up. Anyway, jQuery, try using .each() :

     $.fn.preloadImage = function() { this.each(function(){ $('<img/>')[0].src = this; }); }; // и так: var arr = [1.png 2.png 3.png 4.png ... 10.png]; $(arr).preloadImage(); 
    • Very logical, thanks! Who else can that will prompt ... - ferrari