[whatwg] window.setInterval if visible.
gman at google.com
Thu Oct 15 12:35:03 PDT 2009
I was wondering if there as been a proposal for either an optional argument
to setInterval that makes it only callback if the window is visible OR maybe
Here's the issue that seems like it needs to be solved.
using setInterval. That's great but it has the problem that even when the
to know to stop animating. So, for a CPU heavy animation using canvas 2d or
canvas 3d, even a hidden tab uses lots of CPU. Of course the browser does
drawing hundreds of thousands of pixels to the canvas's internal image
buffer through canvas commands.
To see an example run this sample in any browser
Minimize the window or switch to another tab and notice that it's still
taking up a bunch of CPU time.
Conversely, look at this flash page.
While it might look simple there is actually a lot of CPU based pixel work
required to composite the buttons with alpha over the scrolling clouds with
alpha over the background.
flash has no problem knowning that it no longer needs to render.
There are probably other possible solutions to this problem but it seems
like the easiest would be either
*) adding an option to window.setInterval or only callback if the window is
*) adding window.setIntervalIfVisible (same as the previous option really)
A possibly better solution would be
Which would only call the callback if that particular element is visible.
It seems like this will be come an issue as more and more HMTL5 pages start
using canvas to do stuff they would have been doing in flash like ads or
games. Without a solution those ads and games will continue to eat CPU even
when not visible which will make the user experience very poor.
Am I making an sense?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the whatwg