views:

58

answers:

2

I am developing a twitter application which references to the images directly from twitter. How can I avoid animated gifs from being played? I wouldn't like to grab the first frame every time an animated gif is displayed, to save CPU and bandwidth resources.

I know that this was asked before, but window.stop() at the end of the page does not work for me in FF (or where and when do I need to call it?).

Is there a better javascript hack? Preferable this should work for all browsers :-)

+1  A: 

This is a bit of a hack, but you could try loading the gif into an iframe and calling window.stop() from inside the iframe (on itself) once the image has loaded. This prevents the rest of the page from stopping.

Jason
will this slow down page rendering?
Karussell
i don't think so, no. try it!
Jason
+1  A: 

Could try this...

var img = document.getElementById('animatedgif');
setInterval(function() { img.src = img.src; }, 1);

You could probably include an interval value of ~15 ms without seeing any animation for most gifs. Works in Chrome at least...

MooGoo