Repository navigation
perf(home): stop preloading the search worker and motion-v - #2672
Conversation
nuxt-workers starts the search worker with new Worker(new URL(...)), so Vite lists the bundle as an asset of the entry and the renderer preloaded its 270 KB on every page. The palette loads it when it opens. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e525-9983-7071-a70a-d5ef82f1ba95
The features grid was the homepage's only use of <Motion>, which made motion-v (about 130 KB) part of the chunks it preloads. It also rendered the items with opacity 0 on the server, so they stayed invisible until hydration. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e525-9983-7071-a70a-d5ef82f1ba95
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Bundle sizeClient 1.31 MB
Largest changes in the server
And 5 more packages or files. Brotli sizes. Changes under 100 B are left out of the tables. Initial page load counts the JavaScript and CSS a route loads before it renders. Measured by nuxt-bundle-analyzer for |
Follow-up to #2656 and #2662, aimed at the homepage's render delay. The LCP element (the hero description) is in the HTML, but Lighthouse delays painting it behind every resource it counts as render-blocking: the stylesheet and every high-priority script. Two of those preloads weren't needed on load.
What changed
nuxt.config.ts):nuxt-workersstarts the search worker withnew Worker(new URL(…)), so Vite records its bundle as an asset of the entry, and the renderer then emitted amodulepreloadfor it on every page. That bundle is SQLite wasm plus comark-content: 270 KB raw, 87 KB transferred, needed only once the search palette opens. Abuild:manifesthook clearspreloadandprefetchon script assets, so the worker loads when the palette first opens.index.vue): it was the homepage's only<Motion>, which made motion-v (about 130 KB raw) part of the chunks the homepage preloads. The fade-in is now a CSS keyframe applied when the section hydrates, which happens as it scrolls into view, with the same 100 ms stagger andprefers-reduced-motionrespected. This also fixes a bug:<Motion>server-rendered the items withopacity: 0, so they stayed invisible until hydration.Evidence
Homepage
<head>on nuxt.com today vs this branch's local build: 105 → 103modulepreloadlinks, the search worker is no longer among them, and no preloaded chunk contains motion-dom. Preloaded JS goes from about 1,170 KB to 1,034 KB raw.The search worker loads when the palette opens, not before:
Both sides built locally (
nuxt build, thennode .output/server/index.mjs),mainat 1b07618 vs this branch, Lighthouse 12.6.1 mobile, performance only, alternating runs.Applied throttling (
--throttling-method=devtools: real CPU slowdown and network shaping), 3 runs each:Simulated throttling (Lighthouse's default, which the CI
lighthousejob and PageSpeed use), 5 runs each:The simulated score goes down even though the page paints earlier. FCP and LCP drop by about 2.4 s in both modes, but simulated TBT jumps from 0 to about 450 ms. That's not new work: main-thread time is about the same (4.0 s vs 4.3 s), with the same long tasks. Simulated TBT only counts long tasks between FCP and TTI. On
main, the roughly 300 ms hydration task finishes before the simulated FCP and counts for 0. With FCP 2.4 s earlier, it lands inside the window. Under applied throttling, where timings aren't modelled, this PR wins on every metric. Expect the CI Lighthouse run and PageSpeed to report a lower score until that hydration task shrinks.FCP and LCP read 15–20 s in simulated mode because Lighthouse simulates its slow network against localhost, so only the difference between the two columns matters. Lighthouse runs from this sandbox vary between runs.
Details
preloadandprefetchon every script asset in the client manifest, not only the search worker. Vite only lists a script as an asset fornew Worker(new URL(…))and similar URL imports, never for chunks the app imports.custom:rspackicon, whose SVG has 132 paths. SVGO saves 1%, and thevscode-iconsRspack icon is a different drawing.eslintpasses on both files. The search palette still returns results, and the features grid renders fully and fades in on scroll with no console errors.ELI5
Every page was downloading the search engine and an animation library before showing anything, even though you only need them when you search or scroll down. Now they wait, so the page shows up sooner. One Lighthouse mode still rates it lower, because an earlier first paint means a chunk of startup work now falls inside the window it measures.