r/javascript • • Nov 03 '26

Our JavaScript hero entrance kept LCP at ~50ms but visibly flashed. Hiding it until scripts loaded pushed LCP to ~1.75s

https://ds-gn.com/blog/javascript-motion-above-the-fold?utm_source=reddit&utm_medium=social&utm_campaign=motion_case_study&utm_content=r_javascript
8 Upvotes

11 comments sorted by

9

u/JeanMeche Nov 03 '26

In my experience we shouldn't trust LCP blindly. What matters is the visual result and the user experience not the metric itself.

Like every metric, it has its caveats. This was also implicitly confirmed by some of the folks working on lighthouse.

2

u/ds-gn Nov 03 '26

Thanks, agreed. Our first version was a good example of that: LCP was around 50ms, but the hero visibly flashed when the animation started. Looking at the number alone, we’d have missed the problem.

What we wanted was for the text to stay visible once it had painted. We ended up keeping the heading static and only animating the small eyebrow above it. LCP helped us compare the approaches, but watching what actually happened on screen mattered too.

Appreciate you pointing that out!

3

u/267aa37673a9fa659490 Nov 03 '26

I just skim the article but one of my reliable way for dealing with LCP shenanigans is to use PerformanceObserver, listen for the paint event, make sure LCP is also FCP, then start loading deferred stuff only after the event fired.

1

u/ds-gn Nov 03 '26

Thanks, that's a solid pattern. We did use PerformanceObserver, but only to measure LCP while testing, not to decide when to start the animation.

Our issue was more about what we animated than when. The hero is server-rendered, so its text paints before any JS runs. Starting the entrance after LCP still meant hiding text people had already seen, and fading the heading made Chrome record LCP again when it faded back in. So what fixed it was animating only small things above the fold. The eyebrow is one of those, and now LCP happens at first paint.

Your approach would be a nicer trigger for the eyebrow than our fixed 500ms delay, though, so we may try it, keeping the delay as a fallback for browsers without LCP support.

Appreciate the tip!

2

u/ferrybig Nov 03 '26

You state that an opacity of 0 causes lcp to ignore it.

Is it only 0 and can you work around it by using 0.01 opacity, or is the threshold higher?

1

u/raks1991 22d ago

Chromium excludes opacity exactly 0 from LCP, not 0.01. So 0.01 should count, but it only improves the metric: the text still looks invisible.

1

u/CobaltPhantom22 Nov 04 '26

That's a pretty significant difference. A hero animation shouldn't come at the cost of nearly 1.7 seconds of LCP. Hiding it until scripts load sounds like a sensible trade-off

1

u/baronoffeces 25d ago

That and $3 will get you a cup of coffee

1

u/gianluca_caruso-6 1d ago

Could the initial CSS show the hero in its final state and skip the entrance animation on first load? That keeps the LCP element visible without flashing through a transitional state.

0

u/[deleted] Nov 03 '26

[deleted] — view deleted comment

1

u/ds-gn Nov 03 '26

Thanks for taking a look! Do you mean the background glows? Those move around as part of the animation. Are you seeing them jump while the page loads, or do you mean they start in different positions each time you refresh?

0

u/[deleted] Nov 03 '26

[deleted] — view deleted comment

1

u/ds-gn Nov 03 '26

Ah, got it, thanks for clarifying! The different starting positions on refresh are intentional, but I see what you mean about the glows appearing abruptly when the scripts load. A quick fade-in sounds worth trying. Appreciate the feedback!