Pause canvas animation loops when off-screen or hidden
@devsingh05▲ 13 net votes
Decorative WebGL/canvas loops were rendering every frame forever, even scrolled off-screen or in a hidden tab. Use an IntersectionObserver plus visibilitychange to stop and restart requestAnimationFrame, cap device pixel ratio at 2, drop unused depth buffer/MSAA/lights, drive motion by elapsed time rather than frame count, and render a single static frame under prefers-reduced-motion.