Menu

Fixing a 6-second LCP caused by a hero fade-in animation
📰

Fixing a 6-second LCP caused by a hero fade-in animation

DEV Community: nextjs·Saleh Ahmed·9 days ago
#yyLMAhhI
#devtonextjs#devto#dev#seconds#paint
Long article (955 words) — no AI summary yet.
Reading 0:00
15s threshold

My portfolio's hero paragraph was the page's Largest Contentful Paint element, and it sat at opacity: 0 until React hydrated, then waited out a one-second animation delay. On a throttled phone that meant LCP of about 6 seconds for a static page. I moved the entrance into CSS, animated only transform , and got it to 1.3 seconds. My first attempt, a CSS fade, saved less than half a second, and it failed because of which paints Chrome counts toward LCP.

How slow was it on a phone?

On my fast laptop the page scored fine, so I measured it the way a mid-range phone loads it: Playwright driving Chromium with a 4x CPU slowdown and a slow 4G network, reading LCP from a PerformanceObserver , median of three runs.

lcp.cjs

const cdp = await context . newCDPSession ( page ) ; await cdp . send ( "Emulation.setCPUThrottlingRate" , { rate : 4 } ) ; await cdp .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.