Performance work done by intuition is almost always wasted. People spend an afternoon micro-optimising a loop while a 3MB hero image loads above it. Measure, fix the biggest thing, measure again.

Measure

Open devtools, Network tab, tick "disable cache", reload. Look at two numbers: total transferred, and what the biggest single item is. Then run Lighthouse. Both are free and take a minute.

For a slow server response, log a timestamp at the start and end of the handler, then around each database call. You are looking for one line that accounts for most of the time — there usually is one.

The usual culprits, in order

Images. Almost always the biggest win on a static site. Resize to the size you actually display, use modern formats, add loading="lazy" below the fold, and set width and height so the layout doesn't jump.

Too many database queries. The classic: fetching a list, then one query per item. Twenty rows becomes twenty-one queries. This is the N+1 problem and it is the most common server-side slowness in generated code.

Fetching everything and filtering in code. Filter and limit in the query.

Blocking JavaScript in the head delaying the first paint.

Fonts that block text rendering until they load. font-display: swap.

Ask for the measurement, not the fix

perf-diagnose.txt
This is slow: <what, and where — first load? a click? a page?>
Here's what I measured: <numbers, or "nothing yet">

Don't optimise anything yet.
1. Tell me exactly how to measure this — tool, and what number matters.
2. List the likely causes for this kind of slowness, ordered by how
   often each turns out to be the real one.
3. Which single measurement distinguishes between them?

I'll come back with numbers.

Know when to stop

A page that loads in under a second on a phone on 4G is finished. Users cannot perceive the difference between 400ms and 300ms, and the effort to get there is better spent on the thing the page actually does.

The fastest code is the code you didn't include. Before optimising a library, check whether you need it at all.