The question says it all.
Why does my animated website lag on cheap laptops, and how do I fix it?
1 answer
Chosen as the best answer
Usually the page is doing too much in every frame: reading layout while it animates, stacking full-screen effects, and drawing at a high pixel ratio. Test on a cheap laptop, keep each frame under about 16 ms, and let the page lower its own quality when it falls behind.
A page with 3D, particles and smooth scrolling can run perfectly on a gaming PC and stutter on a laptop with Intel graphics. Most of your visitors have the laptop.
Know your budget
For 60 frames a second, each frame gets about 16.7 ms for everything: your JavaScript, layout, painting and the GPU. On a weak laptop the GPU alone can eat most of that. Open DevTools, record a few seconds in the Performance panel while it lags, and look for the long frames. Don't guess.
The usual causes
Reading layout during the animation. Calling
getBoundingClientRect(),offsetHeightorscrollTopafter changing styles forces the browser to recalculate layout right there, sometimes several times a frame. Read those values on scroll or resize, store them, and only write styles insiderequestAnimationFrame.Too many full-screen effects. Bloom, blur and colour grading each redraw the whole screen. Merge them into one shader pass, or drop the ones nobody would notice.
Too many pixels. A pixel ratio of 2 means four times the pixels of 1. Cap it:
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5));On moving 3D, almost nobody can see the difference between 1.5 and 2.
Work that never stops. Pause the animation when the canvas is off screen (
IntersectionObserver) or the tab is hidden (visibilitychange). Run one animation loop, not three.Lots of separate objects. Thousands of meshes means thousands of draw calls. Use instancing for repeated things, and keep textures no bigger than they show on screen.
Let the page adjust itself
Some machines will still be slow. Measure the average frame time over a second or two. If it stays over budget, lower the pixel ratio or turn off the heaviest effect, and step back up when it recovers. Strong machines get everything, weak ones still get smooth motion.
Keep one cheap laptop around, or use CPU throttling in DevTools, and test there before every release. And respect
prefers-reduced-motionfor people who need the page to stay still.
Your answer
Know the answer? Sign in and share it. Useful answers earn points.
Sign in to answer