Lesson 1 of 3
Measuring before you optimise
2 min
Guessing why a site is slow wastes days. Measure first, then fix the biggest cost.
Split the request into parts
A page load has three distinct costs:
- Time to first byte (TTFB): how long the server takes to answer. Mostly code and database.
- Download: page weight, image sizes, compression.
- Rendering: scripts and styles the browser must process.
Measure TTFB from the command line:
curl -o /dev/null -s -w "%{time_starttransfer}\n" https://yourcompany.com/Above 0.6 seconds usually means server-side work is the problem.
Find the slow part on the server
- Enable the database slow query log (
long_query_time = 1) and read it after a busy day. - Check PHP-FPM's status page for workers that are all busy.
- Watch
topduring peak hours: is it CPU, memory (swap use), or disk wait (wa)?
Front-end checks
Run Lighthouse or PageSpeed Insights and focus on Largest Contentful Paint. The usual fixes are resizing images, serving WebP/AVIF, and deferring scripts that aren't needed at first paint.
Change one thing at a time and measure again. Otherwise you never learn which change helped.