Skip to content

perf: defer client head on the homepage - #714

Closed
harlan-zw wants to merge 2 commits into
mainfrom
perf/homepage-demand-head
Closed

harlan-zw wants to merge 2 commits into
mainfrom
perf/homepage-demand-head

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Use /?head=lazy to opt into delayed client head rendering. Slow and unknown connections warm the renderer and its options early. Cloudflare Analytics renders in the server HTML.

Regular visits use Nuxt's eager renderer. The Worker preview saved 72 ms of main-thread CPU at 80 ms RTT and added 193 ms at 250 ms RTT. The first title update was 13 ms slower and 67 ms faster, respectively. This pilot pins the lazy runtime to an exact revision from Unhead #1063.

Opt-in visits queue head entries and load the renderer when needed. Regular visits preload Nuxt's eager renderer.

🤖 AI disclosure: Harlan Agent Kit modified this description. My AI open-source policy.

Keep the server head during hydration so visits that stay on the homepage can skip renderer work. Warm lazy chunks on slower connections and render the analytics beacon on the server.
@harlan-github-agent

harlan-github-agent Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🤖 CLOSED

Harlan Agent Kit posted this automated review. It is not Harlan's personal review or approval. AI open source policy. Last updated: 2026-11-22 02:37 UTC.

GitHub closed this pull request. No further automated Review will run.

The preview showed a first-navigation delay and mixed startup CPU. Keep the eager path for ordinary visits and start slow-network warming before hydration finishes.
@harlan-github-agent harlan-github-agent Bot added the harlan-agent-ready The automated Review passed every gate on this head commit. label Nov 22, 2026

@harlan-github-agent harlan-github-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Harlan Agent Kit posted this automated review. AI open source policy.

Automated Review: READY.

Read the Review results

Optional follow-ups

Logged (74/100) · Eager routes now wait on a dynamic import during Nuxt startup

The module replaces Nuxt's client head plugin for every production entry. The stock plugin installed the head synchronously. Bare `/` and other eager entry routes now start the wrapper and suspend Nuxt plugin setup on a dynamic import. The server's modulepreload hint can start fetching the chunk earlier, but setup still waits for import resolution before later plugins can run.

Optional follow-up: Keep the stock renderer in the synchronous client startup path for eager entries.

View code

Logged (68/100) · A failed lazy import can leave the destination with the homepage head

On the pilot, a rejected renderer or options import clears the cached promises and logs the error. Navigation and head writes call `load()` without awaiting it, so the destination page can finish while its title and metadata remain queued. If the last activation attempt fails, the settled page has no recovery until another call triggers `load()`.

Optional follow-up: Fall back to the eager renderer on import failure and replay the queued head entries.

View code

Logged (56/100) · Head changes made during hydration can stay queued indefinitely

A normal entry patch before `app:suspense:resolve` changes the queue without starting the renderer. Nuxt's suspense hook calls `head.render()`, which returns `false` while the lazy shell is inactive. The wrapper then marks hydration complete without flushing any queued changes. A client-only title or metadata update during mount can therefore remain invisible for the entire visit.

Optional follow-up: Flush hydration-time changes that differ from the server head when suspense resolves.

View code

Logged (53/100) · The rollout diagram omits the homepage pilot URL

The diagram labels the green path “Homepage HTML and chunk names” and assigns the eager preload to “Other routes.” The server emits the lazy marker only for a non-streamed request to `/?head=lazy`. A reviewer opening bare `/` to validate the diagram measures the eager branch. [Controller image 1](https://github.com/user-attachments/assets/deefa201-0578-4a9a-8587-83e1f44b7c9f)

Optional follow-up: Label the lazy branch `/?head=lazy` in the diagram and name that URL in the pull request description.

View code

Logged (48/100) · The options chunk can be prefetched before the pilot checks connection speed

The options branch records its chunk and exits before clearing `preload` and `prefetch`. The pinned Vue bundle renderer gives JavaScript chunks both flags by default and collects hints for dependencies of dynamic imports. Suppressing the eager entry's own hint therefore still leaves its shared options dependency eligible for an SSR prefetch on the fast-connection pilot, ahead of the client connection check.

Optional follow-up: Suppress default SSR resource hints for the options chunk and let the route-specific loader schedule it.

View code

Logged (22/100) · A question mark inside a query value can disable the pilot

Splitting the request path on `?` with a limit of two discards everything after a second literal question mark. A valid request such as `/?source=docs?ref&head=lazy` therefore loses the selector and silently runs the eager control.

Optional follow-up: Parse the request URL and read the selector from its search parameters.

View code

@harlan-zw harlan-zw closed this Nov 22, 2026
@harlan-github-agent harlan-github-agent Bot removed the harlan-agent-ready The automated Review passed every gate on this head commit. label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant