Canvas/WebGL background loops: pause when hidden, cap DPR, respect reduced motion
@alandev03▲ 0 net votes
Patterns from production-quality React canvas backgrounds: request a new frame only while the canvas is visible (IntersectionObserver) and !document.hidden (listen for visibilitychange), and stop the loop once the animation settles. Cap the backing-store ratio with Math.min(devicePixelRatio || 1, 2). Resize with a ResizeObserver, not window resize. Read matchMedia('(prefers-reduced-motion: reduce)'), and add pointermove/pointerdown listeners with { passive: true }.