Measure web performance before you optimise
"The site feels slow" is not something you can fix. "The largest image on the home page takes 3.1 seconds to appear on a mid-range phone" is. Before changing any code for performance, I measure, find the biggest cost, fi
"The site feels slow" is not something you can fix. "The largest image on the home page takes 3.1 seconds to appear on a mid-range phone" is. Before changing any code for performance, I measure, find the biggest cost, fix that, and measure again.
What to measure
For websites, Google's Core Web Vitals are a good starting set because they describe what a visitor actually experiences:
- Largest Contentful Paint (LCP): when the main content appears. Aim for under 2.5 seconds.
- Interaction to Next Paint (INP): how quickly the page responds to taps and clicks. Aim for under 200 milliseconds.
- Cumulative Layout Shift (CLS): how much the layout jumps while loading. Aim for under 0.1.
For an API, measure latency percentiles (p50, p95, p99) per endpoint, not averages. One slow query hides easily in an average.
Lab data and field data
Lab data comes from a controlled run: Lighthouse, WebPageTest, or the Performance panel in Chrome DevTools. It is repeatable and shows you why something is slow.
Field data comes from real visitors: the Chrome User Experience Report, or the web-vitals library sending numbers to your own endpoint. It tells you whether the problem matters to real people on real devices.
Use field data to choose what to fix and lab data to work out how.
Common findings and fixes
When I audit a site, the same few problems account for most of the slowness:
-
Unsized or oversized images. Serve modern formats (AVIF or WebP), use
srcsetso phones download smaller files, setwidthandheightto prevent layout shift, and addfetchpriority="high"to the LCP image. -
Render-blocking fonts and CSS. Self-host fonts, subset them, use
font-display: swap, and preload only the one or two files needed above the fold. -
Too much JavaScript at startup. Lazy-load routes and heavy components. In Angular,
@deferblocks load a component only when it scrolls into view. - No server rendering for content pages. SSR or prerendering puts the text in the first response, so LCP no longer waits for the JavaScript bundle.
-
N+1 queries on the backend. One query per item in a list. EF Core's query logging or a profiler shows them quickly;
Includeor a projection usually fixes them.
Keep the numbers from slipping
A fix that is not guarded comes back. Two cheap guards:
- A performance budget in the build, for example a maximum initial bundle size in
angular.json, so the build fails when it is exceeded. - Lighthouse CI on pull requests for the most important pages.
Change one thing at a time
When several changes ship together and the numbers improve, you don't know which change helped. When they get worse, you don't know which to revert. Make one change, measure it, and keep a short log of what each change did. It is slower in the moment and much faster over the life of a project.
Originally published on mkcodestudio.com.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.