Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is jquery's attr() asynchronous?

Say I have a loop that on each iteration it appends a div with an img tag, then loads its src attribute using something like this:

$("img").last().attr('src', imageSource);

If I'm doing this for a few iterations for a few different images, am I getting an asynchronous loading of those images?

If not, how do I load images asynchronously by looping? I'll be happy to get some ajax tips.

like image 351
user1639431 Avatar asked Jan 15 '23 15:01

user1639431


1 Answers

attr is not asynchronous. It is a very simple operation that takes place effectively instantly.

However, the loading of the images from the server takes rather longer. That process is asynchronous: as soon as you set the attribute, you can forget about it and the browser will load the image for you in the background.

Loading images asynchronously isn't an option: it is in fact the only way that images are loaded.

like image 78
lonesomeday Avatar answered Jan 20 '23 15:01

lonesomeday