For HTML5 games,with canvas animation for mobile devices.
I\'m facing some performance issues which differ the speed between each device and the others.
OPTIMIZATION requestAnimationFrame() since its introduction was very CPU friendly, causing animations to stop if the current window or tab is not visible.
https://flaviocopes.com/requestanimationframe/
var count = 0;
const IDS = requestAnimationFrame(repeatOften);
function repeatOften() {
count++;
if(count > 4 ){
// cancelAnimationFrame (IDS);
console.warn('finish');
return;
}
console.log('init' + count);
// Do whatever
requestAnimationFrame(repeatOften);
}