I posted something about this in the whatwg list and was told to bring it
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.
There may be other solutions. The advantage to this solution is it requires
almost no changes to logic of current animating applications.
Some have suggested the UA can solve this but I don't see how a UA can know
applications run using setInterval even when not visible so just stopping
non-visible pages from running at all is not an option.
Another suggested solution is for pages to default to only be processed when
visible and requiring the page to somehow notify the UA it needs processing
even when not-visible. This could break some existing apps but they would
likely be updated immediately. This solution might lessen the probability of
and other apps become more common since the default would be for them not to
hog the CPU when not visible.