Notes · Performance · Core Web Vitals · React

Optimising an animated portfolio without removing the animation

How I cut the character pages from 5.6 to 3.6 s on mobile and removed a 72 px layout shift, without touching the style.

Published: · 5 min read · REPO

This site has a lot of motion: layered scenes, a 3D shelf and animated entrances. I wanted to measure what all that cost on a mid-range phone before deciding what to remove. In the end I removed nothing; the problem was elsewhere.

Measure first

I measured the production build in Chrome, simulating a slow 4G network and a CPU four times slower. The character pages took 5.6 s to paint their main image (LCP) and the page jumped 72 px once it finished loading (CLS 0.085).

A margin that went through the page

The chapter bar had a margin-top to make room for the fixed navigation. Being the first element, that margin collapsed through its containers and pushed the whole page down once the chapter loaded. Swapping it for padding on the container brought CLS to zero.

/* Antes: el margen colapsa a través de <main> */
.vol-bar { margin-top: var(--v-nav); }

/* Después */
.ch { padding-top: var(--v-nav); }

An invisible image does not count

The background scene faded in from opacity 0. For the browser an invisible element is not painted yet, so LCP waited for the animation. It now starts at 25 % and has fetchpriority="high".

Images the size of the screen

On a phone the scene shows at about 1000 px wide, but it downloaded at 1900 px. I generated mobile versions and serve them with <picture> below 900 px. Astrid’s page went from 959 to 561 KB on mobile.

What is left

  • The Supabase client (55 KB) now loads when the browser is idle, not on first load.
  • The remaining 3.6 s come from the scene only being discovered once React renders the route. Going lower needs routes with their own HTML.
Could something like this help your project? I work as a freelance web developer. Write to me