Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it true that GIF animation runs on the same thread as javascript in all mainstream browsers?

I show an animated GIF that runs while my AJAX request is in progress and gets stopped once my script has processed the response.

While this works, I notice that while the response from the request is being processed in my script (which contains some fairly heavy updating of the DOM) the animation freezes.

My research leads me to believe that this is because the animation of the GIF happens on the same thread that javascript is running on - that the browser is truly single-threaded. Is this the correct interpretation for all current mainstream browsers (e.g. Chrome, Firefox, Safari, IE)?

Secondly, why is it done this way? Is it really not possible that the browser could dedicate a thread to GIF animations so they didn't freeze when a block of javascript was being executed?

Update

This is an interesting page. It talks about using pure CSS3 animations. They still freeze in Firefox though - maybe soon FF will fix this. Looks like I should be considering CSS for animation rather that using a GIF.

like image 832
Craig Shearer Avatar asked Jun 04 '13 21:06

Craig Shearer


1 Answers

I suppose the problme is (IMHO) that when you update the dom the browser do not repaint the page, so the image freeze.

Try to do heavy thing without change dom, the gif should animate (slowly if your cpu is busy) but not freeze.

If it freeze anyway you could explicitly create a new thread for that work (using webworker) but if i remember right you could not change dom form a webworker.

like image 71
Raji Avatar answered Nov 15 '22 19:11

Raji