← All posts

Engineering · 2026.10.10 · 5 min

One Unread Response Body Made Lighthouse Time Out Every Time

EZLO's mobile PageSpeed score was 46 and Lighthouse timed out on every run. The main cause was an unread body on anonymous refresh requests. After fixing it, public pages stopped checking login state entirely.

Reading
Theme
Size
Width

EZLO's homepage scored just 46 on mobile PageSpeed, and my self-hosted OpenSEO, which measures with Lighthouse, timed out on every run. The main cause wasn't the WebGL background I first suspected. When an anonymous visitor's refresh call got a 400, the frontend never read the response body. Chrome never reported that request as finished, so Lighthouse kept waiting for the network to go idle. Reading the body, then dealing with WebGL, the LCP image, Sentry and fonts, brought the score to 61 and TBT from 410 ms down to 30 ms. Along the way I also realized the public pages don't need to know login state at all, so I removed the probe entirely.

The main cause: one unread body

When an anonymous visitor opens a public page, the frontend calls /api/auth/refresh to try to get a new token, and the backend returns 400. The frontend looked at the status, considered it handled, and never read the body.

Users can't tell the difference, but Chrome doesn't report the request as finished. Lighthouse waits for network idle before it considers the page loaded, and with the request still hanging, it waits until its 45-second limit.

At first I blamed the timeout on the WebGL background. At one point I declared WebGL ruled out, then took that back, and went around in a circle. What finally settled it was testing live with CDP: without reading the body, there's no loadingFinished event; read it, and the event shows up. I couldn't reproduce it locally with an HTTP/1.1 fake backend no matter what I tried. It only shows up in an environment with Cloudflare in front.

The fix was reading the body in performRefresh. Once fetch returns a response, read the body even if you don't need it.

Illustration: when an anonymous refresh request gets a 400 and the frontend never reads the body, the request never finishes and Lighthouse keeps waiting for network idle until its 45-second limit times out; reading the body in performRefresh fires loadingFinished, the network goes idle and the run completes.

Four other things

Without a GPU, the WebGL background renders on the CPU. Now, without hardware acceleration it draws a single frame as a static background. With acceleration, the animation waits until after load, so it doesn't compete with the first screen for the main thread.

On mobile, the LCP element was a CSS background image the browser only discovered after parsing the CSS, while the hidden desktop hero image and the footer image were being preloaded. Now the LCP image is preloaded only on mobile, the desktop hero only downloads on desktop, and the footer image is lazy-loaded.

The Sentry SDK was loaded with a dynamic import and came in whole, 147 KiB over the wire. Switching to named imports of just the parts I need brought it down to 27 KiB.

Font downloads on the Traditional Chinese pages totaled 1.39 MB, with Noto Sans TC accounting for 964 KB. Dropping weights didn't help, since 400, 500 and 700 share the same variable font files. Switching the whole site to system fonts would save the most, but it would change how desktop looks. In the end, only body text on Traditional Chinese pages narrower than 1023px uses system fonts, and desktop and English pages are unchanged. Font downloads on the mobile homepage went from 1,385 KB to 421 KB.

Four other fixes: the WebGL background draws one static frame without hardware acceleration and otherwise animates only after load; the LCP image is preloaded only on mobile, the desktop hero only downloads on desktop and the footer image is lazy-loaded; named imports cut the Sentry SDK from 147 KiB to 27 KiB over the wire; system fonts for Chinese body text under 1023px cut mobile homepage font downloads from 1,385 KB to 421 KB.

Results

Rerunning mobile PageSpeed on the homepage after deploying:

Bar chart of mobile PageSpeed on the homepage before and after: Performance 46 to 61, FCP 9.7 s to 5.0 s, LCP 14.5 s to 9.0 s, TBT 410 ms to 30 ms, Best Practices 96 to 100.

Google doesn't have real-user data for ezlo.me yet, so this score doesn't affect ranking right now. The real gains this time were that the measuring tool can finally produce a number, and faster load times on phones.

Also, Lighthouse's simulated FCP jumps between 2 s and 9.7 s. If the fonts finish downloading before first paint, they get counted as render-blocking resources, so a single run's score is easy to misread.

Public pages no longer check login state

While fixing refresh, another problem surfaced. Every public page probed /me on mount to decide whether the top-right corner showed "Log in" or an avatar. The JWT cookie is HttpOnly and set on the API domain, so the frontend can't read it and only finds out by making the call. Anonymous visitors are the vast majority, so that came to 4 extra requests per page in exchange for one icon in the corner.

I changed direction three times. First I added a localStorage "has logged in before" flag. Then I noticed the site has no way to change your avatar anyway. Only after that did I realize the homepage doesn't need to know login state at all.

The final design: the top-right of every public page always shows "Log in". Clicking it goes to the login page, which probes /me and sends users who are already logged in straight to the dashboard. The login page takes a next parameter for where to go after login, but only accepts on-site paths under /dashboard. External URLs, protocol-relative forms like //host and paths containing .. all fall back to the dashboard home, so the parameter can't be turned into a link that redirects people to another site.

I also considered having the backend add a session endpoint that always returns 200, but that's still an extra request, and it would mean changing the backend.

After the change, an anonymous visitor opening the homepage triggers only three public API requests, with no console errors. Looking back, the first version's flag plus avatar was building machinery for a feature nobody needed.

Wrap-up

  • Read the fetch response body even if you don't use it, or measurement tools may never see the request finish.
  • Performance problems are often several things stacked together. Fix the measurement first so it produces a number, then take the problems apart one at a time.
  • For network behavior you can't reproduce locally, watch the events with CDP in the real environment.
  • Before adding a mechanism, check whether the feature needs to exist.
#Web Performance#Frontend#Next.js#Lighthouse

Letters

Loading comments…

Next

Engineering

Using the CRAP Metric to Find the Functions That Most Need Tests

With mostly agent-written code, high line coverage couldn't show whether the gaps sat in the most complex functions; a CRAP threshold of 8 cleared 200-plus offending functions and turned up 72 issues to fix.