Why your site is slow, and where to look
Most slow sites are not slow because of the server. A methodical tour of where the time actually goes, in the order you should examine it.
"The site is slow" is a symptom, not a diagnosis. Before changing hosting — often the first instinct, and rarely the right answer — you need to know where the time goes.
Here are the places to examine, in order, from most often guilty to least.
First: measure, do not guess
Two kinds of measurement exist, and they say different things.
Lab measurements replay a load under controlled conditions. Reproducible, handy for comparing before and after. But they describe a machine that is not your visitors'.
Field measurements come from real loads by real users. Messier, and infinitely more honest.
The gap between them is often considerable, and almost always in the same direction: your site is slower than you think, because you test it on a good machine, on a good connection, with its cache already warm.
The three indicators that matter
- Time to main content — when the largest visible element appears. This is what a user perceives as "the page is here".
- Visual stability — whether the layout jumps during loading. A button that moves as you click it is one of the most unpleasant things on the web.
- Interaction responsiveness — the delay between a click and a visible response.
Note that none of the three measures server speed.
1. Images
The first place to look, and in most cases the main culprit.
The classic mistakes:
- A 4000-pixel-wide image displayed in a 400-pixel box. The browser downloads all of it, then shrinks it. You paid ten times the necessary weight.
- PNG for a photograph. PNG is lossless, therefore enormous for a photo. JPEG, WebP or AVIF do far better.
- No dimensions in the HTML. Without
widthandheight, the browser does not know how much space to reserve: text jumps when the image arrives. This is the leading cause of visual instability. - Loading everything immediately, including images three screens down.
What to do: size images to their actual display size, serve WebP or AVIF, always state dimensions, and defer loading of what is not visible — except the main image at the top of the page, which should on the contrary be prioritised.
2. Fonts
Often underestimated, and yet highly visible.
A font loaded from a third-party service adds a DNS lookup, a connection, a TLS negotiation, then the download — before a single character appears in the right typeface.
Three measures:
- Self-host the fonts. That removes an entire connection chain to another domain. It is also simpler under a strict content security policy.
- Use
font-display: swapso text appears immediately in a fallback face, then switches. Readable text now beats white space. - Limit the number of weights. Each weight is a file. Two are almost always enough.
3. JavaScript
A 300-kilobyte library to animate a menu is 300 kilobytes to download, parse, compile and execute — on a mid-range phone, not on your laptop.
Downloading is only the first part of the cost. Parsing and execution occupy the main thread, during which the page does not respond to interaction. That is precisely what the responsiveness indicator measures.
The useful questions:
- Does this component need to be interactive, or does it merely display content? Anything that can be rendered on the server need not be sent to the browser.
- Does this dependency earn its weight? Many common needs — dates, HTTP requests, simple animations — are covered by native APIs today.
- Is this code needed for the first render, or can it be loaded on demand?
4. Caching
A file already in cache costs nothing. A file re-downloaded on every visit costs on every visit.
The right strategy depends on one property: does the file name change when its content changes?
- Versioned name (
app.3f2a1b.js): the content behind that URL will never change. Cache for a year,immutable. - Stable name (
/,/about): the content may change. Short lifetime, with revalidation.
The frequent mistake is a long cache on a stable-named file. Visitors then hold a stale version for weeks, and you do not see it because your own browser has been cleared.
5. Server response time
Only now.
If the server takes 800 milliseconds to produce the HTML, everything else starts 800 milliseconds too late. The usual causes, by frequency:
- Database queries in a loop. Displaying twenty articles and querying the database twenty-one times — once for the list, then once per article for its author. This is the most common problem, and it shows up immediately in query logs.
- Missing indexes. A query scanning an entire table is fast with a hundred rows and slow with a hundred thousand. The problem therefore appears after going live.
- Calls to external services during rendering. Each call adds its latency, and if the third party is slow, so is your page.
- Unnecessary dynamic rendering. A page showing the same content to everyone can be generated once and served as is.
Static rendering changes everything
A page generated in advance and served from disk responds in a few milliseconds, because there is no database and no rendering at request time.
The difficulty is content that changes. Incremental regeneration solves that: pages are static, and regenerated when the content is edited. You keep static speed with dynamic freshness.
6. The network
Last, because it is rarely the main problem — but when it is, no application optimisation compensates.
A server in Zurich and a visitor in Zurich: a few milliseconds. The same server and a visitor in Montreal: a hundred milliseconds per round trip. And a page needs several.
Two levers:
- Reduce the number of round trips. Fewer resources, fewer connections, fewer redirects. A redirect costs a full round trip to display nothing.
- Move the content closer. A content delivery network places copies near visitors. Very effective for static files.
And if your audience is local, the network path matters as much as distance: two machines in the same city can be forty milliseconds apart if traffic transits through Frankfurt for lack of direct interconnection. That is a topology problem, not a code one.
Measuring with the right tools
Three tools are enough, and they answer different questions.
The browser's network panel shows what is downloaded, in what order, and how long each resource takes. This is where you see a 3 MB image or a font blocking rendering. Remember to tick "disable cache", and to simulate a slow connection — your fibre lies about the real experience.
A performance audit gives a score and recommendations. Useful for a first pass, but the score itself does not matter: the detailed metrics do. Optimising for the score rather than the user is a classic trap.
Server logs tell you how long your code took, independent of network and browser. If the server answers in 30 ms, there is nothing to find there.
# Server response time, without the browser
curl -s -o /dev/null -w \
"connect: %{time_connect}s tls: %{time_appconnect}s first byte: %{time_starttransfer}s total: %{time_total}s\n" \
https://example.com
time_starttransfer is the number to watch: it is time to first byte, so the server's work. The gap between it and time_total is transfer time.
The trap of measurements that measure themselves
Two methodological errors that completely distort a diagnosis.
Testing from the hosting machine. curl localhost eliminates the network, DNS and TLS. The result is excellent and describes nothing a visitor experiences.
Testing with a warm cache. The second visit is always fast. What matters is the first — a new visitor, with nothing cached, deciding within seconds whether to stay.
And a third, subtler one: a command-line tool does not see what the browser enforces. A content security policy blocking a stylesheet, a script that throws, a refused font: curl returns 200 and some bytes, while the browser renders a broken page. The final test is always a real browser, on the real domain name.
The order to work in
- Measure in the field, not only in the lab.
- Fix the images. Almost always the biggest gain for the least effort.
- Check fonts and the JavaScript you ship.
- Check the caching strategy.
- Look at database queries.
- Consider static rendering, geographic distribution, the network.
And above all: do not change hosting first. It is the most expensive action and the least often effective. A server twice as fast halves a 50-millisecond response time, while your images are costing 3000.
Tags
- Next.js
- Hosting
- Deployment