perf: preconnect to cross-origin hosts on the critical path - #474
Draft
alukach wants to merge 1 commit into
Draft
Conversation
Neither origin is known to the browser until late in the load: - assets.radiant.earth serves the four Berkeley Mono @font-face URLs declared in globals.css, so it is only discovered once that render-blocking stylesheet parses — 5247ms into a real-throttled 4G load. The connection handshake then starts cold. - The Ory session request to /sessions/whoami is flagged by Lighthouse as a preconnect candidate worth 272ms of LCP. crossOrigin is set on the font host only: fonts are fetched in CORS mode and need an anonymous socket, while the Ory session request is credentialed and needs a normal one. The auth hint is conditional because CONFIG.auth.api.backendUrl is empty in dev, where middleware serves auth pages locally. Refs #471
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Claude finished @alukach's task in 1m 14s —— View job ✅ No blocking issues — safe to merge.
Nothing to flag — the diff is small, self-contained, and the two hints are each justified by a genuinely cross-origin, render-relevant host. |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #471.
What
Adds two
preconnecthints in the root layout. The app currently has nopreconnectordns-prefetchanywhere.Why
Neither origin is known to the browser until late in the load:
assets.radiant.earthserves the four Berkeley Mono@font-faceURLs declared insrc/styles/globals.css. The browser can't discover them until that render-blocking stylesheet parses — 5247 ms into a real-throttled 4G load — so the TCP + TLS handshake starts cold at the worst possible moment./sessions/whoami) is flagged by Lighthouse as a preconnect candidate worth 272 ms of LCP.Details worth reviewing
crossOriginis set on the font host only. Fonts are fetched in CORS mode and need an anonymous socket; a preconnect withoutcrossoriginwould open the wrong kind of connection and the font would pay for a second handshake. The Ory session request is credentialed, so it needs the normal (non-anonymous) socket — addingcrossoriginthere would be the same mistake in reverse.The auth hint is conditional.
CONFIG.auth.api.backendUrlis empty in dev, where middleware serves auth pages locally, and<link rel="preconnect" href="">would resolve to the page's own origin. I usedbackendUrlrather thanfrontendUrlbecause/sessions/whoamiis a Ory backend/SDK call. Env is read viaCONFIGper the project convention rather thanprocess.envdirectly.The href is passed whole —
preconnectuses the origin of the given URL, so no parsing is needed even if the value carries a path.Follow-up
The real fix for the font is self-hosting it via
next/font/local, which would put it on the same connection and allow a genuine preload. That's blocked on a licensing decision (Berkeley Mono is commercially licensed and this is a public repo) — tracked in #471.preconnectis the safe interim step.Verification
npm run type-check— 14 errors, identical to the count on cleanmain(all pre-existing, inanalytics/files)🤖 Generated with Claude Code