Work out the sizes attribute from your layout instead of copying it from a blog post. Performance work goes wrong when it starts with a guess. Every change in this post began with a measurement on real hardware and ended with a second measurement to prove it helped.
Measure before you touch anything
Field data from real users tells you where the problem is; lab tools tell you why. We start with the Core Web Vitals report, pick the worst page template, and only then open the profiler.
<img
src="/img/hero-800.jpg"
srcset="/img/hero-400.jpg 400w, /img/hero-800.jpg 800w, /img/hero-1600.jpg 1600w"
sizes="(min-width: 1024px) 720px, 100vw"
width="1600" height="900"
alt="Dashboard showing request latency"
fetchpriority="high"
/>
The change that mattered
The biggest single win was rarely clever. Right-sized images, fewer third-party scripts, and a cache header on static assets did more than any amount of micro-optimisation in our own code.
- Start from field data, not a lab score.
- Fix the largest resource first.
- Compare percentiles, not single runs.
- Re-measure a week later.
Verifying the win
After each change we compare the median and the 75th percentile, not the best run. A fix that only helps fast devices is not a fix for the people who were actually suffering.
Before you ship this
Lazy-loading the largest image above the fold makes LCP worse, not better. Give it fetchpriority=”high” instead.
Programs must be written for people to read, and only incidentally for machines to execute.
Harold Abelson, Structure and Interpretation of Computer Programs, 1985
Wrapping up
None of this is new, and that is the point. The techniques that last are usually the boring ones that are documented well and supported by the platform itself.
We run this in production at a fairly large scale and can confirm the caveats are real.
I would push back a little on the second section. In our monorepo the trade-off went the other way.
Great post. Did you measure the impact before and after, or is this mostly from experience?
Shared this with my team. The list near the end is going straight into our pull request template.
The renaming spree is a rite of passage.
We run this in production at a fairly large scale and can confirm the caveats are real.
Came for the snippet, stayed for the explanation.
Any thoughts on how this interacts with server-side rendering?