The Ops Community ⚙️

Cover image for How to Fix Long Animation Frames (LoAFs) and Speed Up Your Website
Todd H. Gardner for Request Metrics

Posted on

How to Fix Long Animation Frames (LoAFs) and Speed Up Your Website

If your website feels sluggish or unresponsive during animations, you’re likely dealing with Long Animation Frames (LoAFs). LoAFs occur when a single animation frame takes longer than 50 milliseconds to render, causing stuttering, lag, or what developers often call “jank.”

The problem is, LoAFs aren’t immediately visible in Chrome DevTools by default. However, you can use the PerformanceObserver API to track and analyze them in real time, helping you identify what’s slowing down your animations.

One of the primary causes of LoAFs is heavy JavaScript execution. Long-running scripts block the main thread and prevent the browser from rendering frames efficiently. To resolve this, break up long tasks into smaller chunks and spread them across multiple frames using setTimeout or other techniques to give the browser time to process animations smoothly.

Another common culprit is forced synchronous layouts, which happen when you modify the DOM and immediately read layout properties like offsetWidth or scrollHeight. To avoid this, batch your DOM reads and writes to minimize layout recalculations, or use transform for animations to avoid triggering expensive reflows.

For modern web apps like Single Page Applications (SPAs), optimizing component re-renders and deferring non-essential JavaScript using code-splitting can also help reduce LoAFs and improve the user experience.

For a more detailed breakdown of how to diagnose and fix Long Animation Frames, check out the full post on LoAFs and how to optimize them here.

Top comments (0)