A Performance Budget for Framer Motion on Mobile in Malaysia
Struggling with Framer Motion mobile performance? We share our practical budget for animations on mid-range devices and how we boosted our Lighthouse scores.
Framer Motion is an excellent library for creating fluid, complex animations in React. At JRV Systems, we use it to add a layer of polish to our projects. However, that polish comes at a cost, especially on the mid-range Android devices common across Malaysia. A beautiful animation that stutters and drains the battery isn't a feature; it's a liability.
This isn't an argument against Framer Motion. It's an argument for a disciplined approach: a performance budget. This means consciously deciding where to spend your JavaScript animation budget and where to fall back on simpler, more performant CSS transitions.
The Challenge of Framer Motion Mobile Performance
Unlike CSS animations which can often run on a separate compositor thread, JavaScript-driven animations—the kind Framer Motion excels at—run on the main thread. This is the same thread that handles user input, parses HTML, and executes other scripts. On a high-end iPhone, this is rarely an issue. On a common device in Malaysia, like a Samsung Galaxy A series or a Xiaomi Redmi, the main thread can easily become blocked, leading to jank, dropped frames, and a poor user experience.
The core issue with Framer Motion mobile performance is that physics-based animations (like springs) and complex staggers require constant recalculation. Each frame, JavaScript is calculating the new position, opacity, or transform. This overhead adds up, impacting key metrics like Interaction to Next Paint (INP) and Total Blocking Time (TBT).
Defining Your Animation Budget
A performance budget isn't just a vague goal; it's a set of concrete limits. Before we even start animating, we define our targets using tools like Google's Lighthouse.
Our baseline at JRV Systems is a Lighthouse Performance score of 90+ on a simulated mobile device (e.g., Moto G4 profile with 4x CPU slowdown). This ensures a good experience for the majority of users. If adding a complex animation drops that score into the 80s, we have to justify its value. Does it significantly improve usability or is it just decorative?
This forces a conversation. Is a staggering list animation on entry worth a 200ms increase in TBT? Usually, the answer is no. A simple, performant fade-in achieves 80% of the effect with 10% of the performance cost.
What to Keep, What to Convert, What to Cut
With a budget in place, we can audit our animations. We categorize them to decide on the right implementation.
-
Keep in Framer Motion: These are animations where the library's power is essential.
- Layout Animations: Animating between different element positions or sizes using
layoutId. Doing this smoothly with CSS is notoriously difficult. This is Framer Motion's killer feature. - Complex Sequences & Staggering: Coordinating animations across multiple elements, especially with delays.
staggerChildrenis powerful for this. - Scroll-Linked Animations: Tying an animation's progress to the user's scroll position using hooks like
useScroll. This is pure JavaScript territory. - Physics-Based Gestures: Draggable elements with momentum or spring-based modal pop-ups.
- Layout Animations: Animating between different element positions or sizes using
-
Convert to CSS: These are simple effects that don't need a JavaScript library.
- Simple Fades:
opacitytransitions on load, hover, or focus. - Simple Transforms: Moving an element slightly on hover (
transform: translateY(-2px)). - Underlines and Backgrounds: Animating the
widthorbackground-colorof an element.
- Simple Fades:
For these, a simple CSS transition property is far more efficient. It's declarative and lets the browser optimize rendering.
Case Study: Optimising jrvsystems.app
When we first built our own site, we used Framer Motion for nearly every animated effect, including simple fade-ins for service cards on the homepage. The result was visually appealing but didn't perform well under pressure.
Our initial Lighthouse audit showed a mobile Performance score of around 78. The main culprits were a high Total Blocking Time and a long time to become interactive. The main thread was busy orchestrating all the entry animations.
Our optimisation process was straightforward:
- We identified all animations that were simple property changes (like opacity and transform).
- We removed the
<motion.div>wrappers from these components and replaced them with simple CSS transition classes. - We kept Framer Motion for two key areas: the navigation link underline, which uses
layoutIdto slide smoothly between items, and the initial page load transition.
The result? Our mobile Lighthouse Performance score jumped from 78 to 94. The site felt snappier, especially on mid-range test devices, and the key metrics improved significantly. We didn't lose the premium feel, but we shed the performance cost.
Respecting User Preferences
Finally, a critical part of any animation strategy is respecting users who prefer less motion. This is an accessibility setting in most operating systems, exposed to the browser via the prefers-reduced-motion media query.
Framer Motion provides a simple hook, useReducedMotion(), that returns true if the user has this setting enabled. We use this to disable or simplify our animations.
For example, a complex staggering animation can be replaced with a simple collective fade-in if useReducedMotion is true. This not only respects the user's choice but also serves as another performance optimization, as it effectively disables heavy JS animations for those who don't want them.
In conclusion, using Framer Motion effectively in the Malaysian market requires restraint. By setting a performance budget, auditing each animation's purpose, and falling back to CSS for simple tasks, we can build websites that are both beautiful and accessible to everyone, regardless of their device.