Vue and Nuxt performance
Measure what Vue's reactivity, shallowRef, v-memo, async components, lazy hydration, Nuxt Image and Nuxt Fonts change on a real Vue and Nuxt shop.
- 01Read what Vue draws againCount the components and rows Vue updates for an input, and see when deep reactivity costs memory.
- 02Skip work in long listsUse v-once, v-memo and row components, and know why v-memo can't help when a filter moves the rows.
- 03Send less, and the right sizesChoose between async components and lazy hydration, and see what Nuxt Image and Nuxt Fonts change for LCP and CLS.
Ben's Vue shop and two clicks
Module 36 looks at this course's ideas through each framework's own tools. Lessons 36.1 to 36.3 did React, Next.js and Angular. This lesson does Vue, and Nuxt, Vue's framework for pages drawn on a server.
Ravi's friend Ben runs the Vue version of the shop. Asha opens his reviews page, the page from lesson 36.1. It has the cart badge, Add to cart, a box to filter, and 1,000 reviews. She clicks Add to cart, and the badge says Cart (1). Then she clicks Helpful on the first review, and the button fills in.
Each click changed one small thing. Yet the second one took twice as long. Why? Here are real frames from Asha's screen:
The course counted what Vue did for each click:
// Asha's two clicks on Ben's first reviews page.// updated: components Vue drew again. rows: reviews drawn again.// ms: from the click to the next paint, the middle of five visits.const clicks = [ { label: "Add to cart", updated: ["CartBadge"], rows: 0, ms: 22.1 }, { label: "Helpful", updated: ["App", "ReviewList"], rows: 1000, ms: 44.8 },];for (const { label, updated, rows, ms } of clicks) { console.log(`${label}: ${updated.join(" and ")} drawn again, ${rows} rows, ${ms} ms`);}- Lines 1 to 3 are comments. A component is one piece of a Vue page, like the badge or the list. Its template is the HTML it draws. A millisecond (ms) is a thousandth of a second.
- Lines 5 and 6 hold each click: the components Vue drew again, the review rows it drew again, and the time until Asha saw the next frame.
- Line 9 prints
Add to cart: CartBadge drawn again, 0 rows, 22.1 ms. Then it printsHelpful: App and ReviewList drawn again, 1000 rows, 44.8 ms.
For Add to cart, Vue drew one small component, the badge. For Helpful, it drew all 1,000 rows of the list again, to fill in one button. Both clicks were well under 200 ms, the line for a good INP (lesson 26.1). But the second click's work grows with the list. Why it matters: on a longer list or a slower phone, Helpful gets slower. The badge doesn't.
You sign up for the tea shop's news about mint tea. When its price changes, a letter goes to everyone who signed up, and to nobody else. But the letter comes to your house, and the whole family reads it.
- In real life: Signing up for news about mint tea
- In Vue: A component reading cart.count while it draws
- In real life: A letter to everyone who signed up
- In Vue: Vue drawing again each component that read the value
- In real life: No letter for anyone else
- In Vue: Components that didn't read it are skipped
- In real life: The whole family reads the letter
- In Vue: The whole template of that component runs again
Vue draws again only the components that read a value that changed. But it draws each of them whole. So keep big templates out of the way of changes, and send less code at the start. v-memo and row components cut the drawing. A shallowRef cuts Vue's bookkeeping. Async components and lazy hydration cut the code at the start. Nuxt Image and Nuxt Fonts fix the photo and the font.
How the course recorded it
- Ben's pages: Vue 3.5.45, built with Vite's production build. The Mint tea page used Nuxt 4.6.4, built with
nuxt build. - Two pages: the reviews page, four ways, drawn in the browser. And lesson 35.3's Mint tea page, six ways, drawn by the server that
nuxt buildwrites. - Asha's phone: Chrome 157, with the CPU 4 times slower. The course's server played a Fast 4G line: 165 ms before each answer, then 8.1 megabits a second.
- Real input: mouse clicks and key presses, sent through Chrome's DevTools protocol. The scroll to the reviews was done by a script.
- Counting: each reviews page was built a second time, with a small counter for every component Vue drew again and every row. The counts were the same in every visit.
- Warm servers: each Nuxt server answered one request for the page and its photo before Asha's visit, as a running server would have.
- 5 visits: each page and way, taking turns. The lesson quotes the middle one.
Vue draws again only what read a change
How did Vue know to touch only the badge? Here is Ben's cart:
import { reactive } from 'vue' export const cart = reactive({ count: 0 }) export function addToCart() { cart.count++}- Line 3 makes the cart with
reactive. It wraps the object in a proxy: a stand-in object that notices every read and every change. - Lines 5 to 7 are addToCart. Add to cart calls it, and line 6 adds one to the count.
<script setup>import { cart } from '../cart.js'</script> <template> <a id="cart" href="#">Cart ({{ cart.count }})</a></template>- Line 2 imports the cart. Line 6 is the badge's template, and it reads cart.count.
Vue draws each component inside a reactive effect: a function Vue runs again when something it read changes. While the badge draws, it reads cart.count. The proxy notes that read (baseHandlers.ts, line 113). When line 6 of the cart changes the count, Vue looks up who read it. Only the badge did, so Vue draws only the badge.
Vue doesn't draw at once. It queues the badge, and runs the queue in a microtask, right after the click's handler (scheduler.ts, lines 130 to 134). So in INP's parts (lesson 26.2), Vue's drawing counts as processing. In the visit the course kept, Helpful's processing was 38.6 of its 45.6 ms. Lesson 36.3's Angular waited for the next frame instead. Why it matters: in a Vue trace, look for Vue's work inside the click's event.
For one letter, lesson 36.1's first React page ran every component again. For one click, lesson 36.3's Eager Angular page checked every template. Vue starts from the value that changed. So why did Helpful draw 1,000 rows? Here is the list:
<script setup>import { marked } from 'marked'import ReviewStars from './ReviewStars.vue' defineProps({ query: String, reviews: Array, votes: Array })const emit = defineEmits(['helpful']) function toHtml(text) { return marked.parse(text)}</script> <template> <section id="reviews"> <p id="count"> {{ query ? `${reviews.length} reviews mention "${query}"` : `${reviews.length} reviews` }} </p> <ul class="reviews"> <li v-for="review in reviews" :key="review.id" class="review" > <h3 class="review-name">{{ review.name }}</h3> <p class="review-date">{{ review.date }}</p> <ReviewStars :count="review.stars" /> <div class="review-text" v-html="toHtml(review.text)"></div> <button class="helpful" type="button" :aria-pressed="votes.includes(review.id)" @click="emit('helpful', review.id)" > Helpful </button> </li> </ul> </section></template>- Line 5 lists the props, the values its parent passes in. votes holds the ids of the reviews marked Helpful.
- Lines 8 to 10 are toHtml. It turns a review's Markdown into HTML with marked, the library from lesson 36.1.
- Lines 19 to 36 are one row. The v-for on line 20 repeats it for each review.
- Line 27 calls toHtml for the row's text. Line 31 reads votes, to fill in the Helpful button.
A template is drawn whole. Helpful gave votes a new array, and every row reads votes on line 31. So Vue drew ReviewList again, with all 1,000 rows, and called toHtml 1,000 times. Each result was the same as before, so the page changed in one place only. Why it matters: what a component reads decides when it's drawn. What's in its template decides what that costs.
A ref, a shallowRef and 1,000 reviews
Ben keeps the reviews in App, the page's top component:
import { computed, ref } from 'vue'import { REVIEWS, matches } from './reviews.js' const reviews = ref(REVIEWS)const query = ref('')const votes = ref([])const shown = computed(() => reviews.value.filter((review) => matches(review, query.value))) function markHelpful(id) { votes.value = votes.value.includes(id) ? votes.value.filter((other) => other !== id) : [...votes.value, id]}- Line 4 puts the reviews in a ref: a box Vue watches. You read and change what's inside through
.value. - Lines 5 and 6 are two more refs: the box's text, and the votes.
- Line 7 is a computed: a value Vue works out from others, and works out again when they change. It keeps the reviews that match the box.
- Lines 9 to 11 give votes a new array when Asha clicks Helpful.
A ref is deep. When it holds objects, Vue makes each one reactive the first time it's read (ref.ts, line 125; baseHandlers.ts, lines 126 to 131). So each review gets a proxy. Each property a component reads also gets a record of who read it (dep.ts, lines 262 to 273). Ben's rows read five properties of each review. That's about 5,000 records.
A library can put an alarm tag on every book. It knows when any book moves, but the tags cost time and money. Or it can tag only the shelf. Then it notices a new shelf, but not a book swapped on the old one.
- In real life: An alarm tag on every book
- In Vue: A ref: a proxy for every review, and a record per property read
- In real life: One tag on the shelf
- In Vue: A shallowRef: only .value is watched
- In real life: Swapping a book on the tagged shelf
- In Vue: Changing a review inside a shallowRef: nobody notices
- In real life: Bringing in a whole new shelf
- In Vue: Giving the shallowRef a new list: every reader updates
A shallowRef is the shelf tag. Vue watches only its .value, and leaves what's inside as it is. markRaw does the same for one object: Vue never makes it reactive. The course ran this with the real Vue:
import { isReactive, markRaw, ref, shallowRef } from 'vue'import { threeReviews } from './three-reviews.js' const deep = ref(threeReviews())const shallow = shallowRef(threeReviews())const raw = ref(markRaw(threeReviews())) console.log(isReactive(deep.value[0]))console.log(isReactive(shallow.value[0]))console.log(isReactive(raw.value[0]))- Line 4 puts three reviews in a ref. Line 5 puts three more in a shallowRef. Line 6 marks three more raw, then puts them in a ref.
- Lines 8 to 10 ask whether the first review in each is reactive. They print
true,falseandfalse.
The catch: a shallowRef doesn't see changes inside it.
import { nextTick, shallowRef, watchEffect } from 'vue'import { threeReviews } from './three-reviews.js' const reviews = shallowRef(threeReviews())watchEffect(() => console.log(`First review: ${reviews.value[0].stars} stars`)) reviews.value[0].stars = 1await nextTick()reviews.value = [{ ...reviews.value[0], stars: 2 }, ...reviews.value.slice(1)]await nextTick()- Line 5 prints the first review's stars, and prints again when what it read changes. It prints
First review: 5 stars. - Line 7 changes the stars inside the list. Vue doesn't see it, so nothing prints.
- Line 9 gives
.valuea new list. Line 5 runs again and printsFirst review: 2 stars.
So a shallowRef suits data you replace, like a list from an API, not data you change in place. How much did the deep ref cost Ben? The course built the page again with line 4 as const reviews = shallowRef(REVIEWS), and measured both:
// The middle of five visits. heap: bytes in use after garbage collection.// mount: ms to draw the 1,000 reviews. helpful and h: ms to the next paint.const pages = [ { page: "ref", heap: 13937140, mount: 279.9, helpful: 44.8, h: 71.2 }, { page: "shallowRef", heap: 13254684, mount: 268.1, helpful: 41.1, h: 66 },];const [deep, shallow] = pages;console.log(`A ref used ${((deep.heap - shallow.heap) / 1000).toFixed(0)} kB more memory.`);console.log(`Drawing: ${deep.mount} ms, then ${shallow.mount} ms`);console.log(`Helpful: ${deep.helpful} ms, then ${shallow.helpful} ms`);console.log(`h: ${deep.h} ms, then ${shallow.h} ms`);- Lines 4 and 5 hold each page: memory in use after garbage collection, the time to draw the 1,000 reviews, and two inputs.
- Line 8 prints
A ref used 682 kB more memory.A kB is 1,000 bytes. - Lines 9 to 11 print
Drawing: 279.9 ms, then 268.1 ms,Helpful: 44.8 ms, then 41.1 msandh: 71.2 ms, then 66 ms.
Memory was the clear part: 682 kB more in every visit. The times were only a few ms apart, and the five drawing times of the two pages overlapped. Vue's docs say deep reactivity shows when one render reads 100,000 properties or more. Ben's reads about 5,000. Why it matters: use a shallowRef or markRaw for big data you only replace. On a list this size, it saves memory, not time.
v-once and v-memo: reuse what didn't change
Vue has two directives for skipping work. A directive is a special attribute that starts with v-. The first, v-once, draws an element once and skips it on every later update:
<script setup>import { cart } from './cart.js'</script> <template> <p id="once" v-once>When you came: {{ cart.count }} in your cart</p> <p id="now">Now: {{ cart.count }} in your cart</p></template>- Line 6 has v-once. Line 7 shows the same count without it.
- The course mounted this with the real Vue, added 3 to the cart, and read both lines. Line 6 said
When you came: 0 in your cart. Line 7 saidNow: 3 in your cart.
v-memo is v-once with a condition. You give it a list of values. When Vue draws the template again, it compares them with last time. If none changed, it reuses the old element and everything inside it. Ben added it to each row:
<li v-for="review in reviews" :key="review.id" v-memo="[votes.includes(review.id)]" class="review">- Line 4 is the only change. A row shows its review, which never changes, and its vote. So the vote is the one value to compare.
// [rows drawn again, ms to the next paint], the middle of five visits.const pages = [ { page: "shallowRef", helpful: [1000, 41.1], h: [900, 66] }, { page: "v-memo", helpful: [1, 15.9], h: [884, 74.7] }, { page: "Row component", helpful: [1, 17], h: [0, 48.8] },];for (const { page, helpful, h } of pages) { console.log(`${page}: Helpful ${helpful[1]} ms (${helpful[0]} drawn), h ${h[1]} ms (${h[0]} drawn)`);}- Lines 3 to 5 hold three pages: the shallowRef page, the v-memo page, and one more you'll meet below. Each holds the rows drawn again and the time, for Helpful and for h.
- Line 8 prints
shallowRef: Helpful 41.1 ms (1000 drawn), h 66 ms (900 drawn). Thenv-memo: Helpful 15.9 ms (1 drawn), h 74.7 ms (884 drawn). Last,Row component: Helpful 17 ms (1 drawn), h 48.8 ms (0 drawn).
v-memo fixed Helpful: one row instead of 1,000. But it didn't fix h. The h hid 100 reviews, and Vue still drew 884 of the 900 rows left. Why?
Look at how v-memo finds the row to compare with. Vue's compiler puts a check before each row: is there a saved row, with the same key and the same values (vFor.ts, lines 218 to 235)? And the saved row it checks is the one from the same place in the last list (renderList.ts, line 90).
A host keeps yesterday's place cards on a long table. If the same guest sits in seat 5 again, the card stays. But if one guest leaves and everyone moves up a seat, every card after that seat must be written again. The host checks by seat, not by guest.
- In real life: A seat at the table
- In Vue: A place in the list: first row, second row...
- In real life: Keeping yesterday's card
- In Vue: Reusing the saved row
- In real life: The same guest in the same seat
- In Vue: The same key and the same memo values at that place
- In real life: Everyone moving up a seat
- In Vue: A filter that hides a review near the top
Reviews 17 and 19 don't mention h, so the h hid them, and every review after them moved up. Only the first 16 places kept their reviews. Why it matters: v-memo helps when rows stay in place, like a vote or a selection. It doesn't help a filter or a sort.
A component for each row
The third page moves each row into a component of its own, ReviewRow. Vue compares a child component's props with last time, and skips it if none changed (componentRenderUtils.ts, lines 407 to 417). The list now says:
<ReviewRow v-for="review in reviews" :key="review.id" :review="review" :voted="votes.includes(review.id)" @helpful="(id) => emit('helpful', id)"/>- Line 4 passes the review. A row that moves still gets the same review object, so this prop doesn't change.
- Line 5 passes voted, true or false, instead of the whole votes list. Only the row whose vote changed gets a new prop.
ReviewRow's template is the same row as before. Vue's docs call this props stability. The numbers are above: Helpful drew one row, and h drew none. That was the fastest h of the four pages. What's left is the list's own work: matching rows to the last list, and removing the hidden ones.
It isn't free. Vue's docs say a component costs more than plain HTML elements, and now there are 1,000 more. The rows page used 1.75 MB more memory than the shallowRef page. Drawing the first 1,000 reviews took 309.7 ms, not 268.1 ms. Why it matters: a row component pays once at the start, to save work on every later input. Measure both.
Pick a page to see what Vue drew again for each of Asha's inputs:
- Memory after the first draw13.94 MB
- Drawing the 1,000 reviews279.9 ms
- Add to cartCartBadge; 0 rows; 22.1 ms
- HelpfulApp, ReviewList; 1,000 rows; 44.8 ms
- Key hApp, FilterBox, ReviewList; 900 rows; 71.2 ms
- Key oApp, FilterBox, ReviewList; 350 rows; 58.1 ms
- Key nApp, FilterBox, ReviewList; 250 rows; 30.6 ms
- Key eApp, FilterBox, ReviewList; 250 rows; 18.7 ms
- Key yApp, FilterBox, ReviewList; 200 rows; 24.4 ms
Pick a page. The first two rows are the page's memory and its first draw. Then each input: the components Vue drew again, the review rows drawn again, and the time until the next paint.
Async components and lazy hydration
Now Asha opens the Mint tea page from lesson 35.3. Ben built it with Nuxt. Nuxt draws the page on its server and sends finished HTML. Then the browser downloads the JavaScript, and Vue attaches the click handlers to that HTML. That's hydration.
The page has 200 reviews far down. Their component brings marked and the reviews' text. Imported as usual, it sits in the entry file, the file every visit runs first. An async component moves it into a file of its own:
import { defineAsyncComponent } from 'vue' const ShopReviews = defineAsyncComponent(() => import('~/components/ShopReviews.vue'))- Line 3 wraps a dynamic import, as in lesson 22.4. Vue's docs say the loader runs only when the component is drawn on the page.
The build gave the reviews a file of their own: 17.9 kB compressed. But look at when Chrome asked for it, on four ways of the page:
// The reviews' code on the Mint tea page. Times in ms from the start.// Asha scrolled to the reviews at about 3,200 ms.const ways = [ { way: "Plain import", file: "the entry file", asked: 196.9, priority: "High", hydrated: 696.5 }, { way: "defineAsyncComponent", file: "its own file", asked: 199.6, priority: "High", hydrated: 721.4 }, { way: "hydrateOnVisible", file: "its own file", asked: 198.6, priority: "High", hydrated: 3273.8 }, { way: "Lazy, hydrate-on-visible", file: "its own file", asked: 208.8, priority: "Lowest", hydrated: 3307.2 },];for (const { way, file, asked, priority, hydrated } of ways) { console.log(`${way}: ${file}, asked at ${asked}, ${priority}, hydrated at ${hydrated}`);}- Lines 4 to 7 hold each way: which file held the reviews' code, when Chrome asked for it, at what priority, and when the reviews hydrated.
- Line 10 prints
Plain import: the entry file, asked at 196.9, High, hydrated at 696.5first, then one line for each other way.
defineAsyncComponent split the file, but Chrome asked for it at once, at High priority. The server had drawn the reviews into the HTML. So the page had to hydrate them at the start, and Nuxt's HTML told Chrome to fetch their file early, with a modulepreload link. Nuxt's docs warn that lazy components "still load eagerly unless conditionally rendered."
Waiting to hydrate
Vue can also wait to hydrate. A hydration strategy tells an async component when to wake up:
import { defineAsyncComponent, hydrateOnVisible } from 'vue' const ShopReviews = defineAsyncComponent({ loader: () => import('~/components/ShopReviews.vue'), hydrate: hydrateOnVisible(),})- Line 5 is the strategy. hydrateOnVisible hydrates the reviews when they scroll into view.
The reviews hydrated 87.1 ms after the scroll, not at the start. But the file still came at once, at High. Vue's async component starts loading as soon as it's set up (apiAsyncComponent.ts, line 237). Only the hydration waits (lines 152 to 156).
Nuxt has its own way: the Lazy prefix on a component's name, with a strategy as a prop:
<LazyShopReviews hydrate-on-visible />- Line 1 is the whole change. Lazy makes Nuxt load ShopReviews as an async component (loader.ts, lines 143 to 154). hydrate-on-visible picks Vue's hydrateOnVisible.
- Nuxt has other strategies too. For example, hydrate-on-interaction waits until a pointer moves onto the component, or someone clicks or focuses it.
Nuxt wraps the component in a second async component, "to avoid loading the chunk too soon" (lazy-hydrated-component.ts, lines 37 to 41). It also left the file out of the preload links. Yet its HTML still had a prefetch link for it. So Chrome fetched it during the load, at the Lowest priority. At the scroll, Vue took it from Chrome's cache in 0.5 ms.
The biggest change was on the main thread. With all the reviews hydrated at the start, the Nuxt Fonts page had a 157 ms long task. With either strategy, there was no long task before the scroll. The reviews' hydration moved to the scroll: 84 ms on the hydrateOnVisible page, 112 ms on the Lazy page. Why it matters: an early click on Add to cart no longer waits behind 200 reviews nobody is looking at.
An office has lights on motion sensors. Every room is there, with its door and its sign. But a room's lights come on only when someone walks in. The building saves power on the rooms nobody visits.
- In real life: The rooms, with their doors and signs
- In Nuxt: The reviews in the server's HTML
- In real life: Lights on in every room at opening time
- In Nuxt: Hydrating every component at the start
- In real life: The motion sensor
- In Nuxt: hydrate-on-visible
- In real life: A room nobody walks into stays dark
- In Nuxt: Reviews nobody scrolls to are never hydrated
Pick a way to see all its numbers. The next section explains the photo and the font.
- High-priority JavaScript69.9 kB
- The reviews' codein the entry file
- Long tasks before the scroll165 ms, 61 ms
- Reviews hydratedat 680 ms, with the page
- The photo102.8 kB, arrived at 545.2 ms
- LCP, the photo716 ms
- CLS, when Lora arrived0.0063
- Helpful pressed, after the click14.5 ms
Pick a way. Each is one change from the way before it. Asha opened the page, waited, scrolled to the reviews, then clicked Helpful on the first one.
Nuxt Image and Nuxt Fonts
Lesson 36.2 used next/image and next/font for the same photo and font. Nuxt's versions are modules. A module is a package that adds features to a Nuxt app:
export default defineNuxtConfig({ modules: ['@nuxt/image', '@nuxt/fonts'], css: ['~/assets/shop.css'], compatibilityDate: '2026-11-01',})- Line 2 adds both modules. Line 3 is Ben's stylesheet.
NuxtImg: a smaller photo, asked for first
Ben's photo was a plain img: a JPEG 1,600 pixels wide, of 102.8 kB. NuxtImg replaces it:
<NuxtImg class="hero" src="/mint-tea.jpg" width="1600" height="1067" sizes="xs:100vw sm:640px" format="webp" :preload="{ fetchPriority: 'high' }" fetchpriority="high" alt="A cup of mint tea"/>- Line 6 is sizes: how wide the photo shows, in Nuxt Image's own short form.
- Line 7 asks for WebP, a smaller format.
- Line 8 asks for a preload link with fetchpriority high. Line 9 puts fetchpriority high on the img too.
Here is what Nuxt's server sent for it:
<link rel="preload" as="image" href="/_ipx/f_webp&s_1280x854/mint-tea.jpg" imagesizes="640px" imagesrcset="/_ipx/f_webp&s_640x427/mint-tea.jpg 640w, /_ipx/f_webp&s_1280x854/mint-tea.jpg 1280w" fetchpriority="high">
<img width="1600" height="1067" data-nuxt-img sizes="640px" srcset="/_ipx/f_webp&s_640x427/mint-tea.jpg 640w, /_ipx/f_webp&s_1280x854/mint-tea.jpg 1280w" class="hero" fetchpriority="high" alt="A cup of mint tea" src="/_ipx/f_webp&s_1280x854/mint-tea.jpg">- Line 1 is the preload link, added to the head on the server (NuxtImg.vue, lines 106 to 124).
- Line 2 is the img. Its srcset lists two widths, 640 and 1,280 pixels. Nuxt's own image server, IPX, makes them under /_ipx/. Lesson 18.2 showed how the browser picks one.
Look at sizes: just 640px. Ben wrote xs:100vw, but Nuxt Image's screen names are sm, md, lg, xl and 2xl. It skips a name it doesn't know (image.ts, lines 210 to 222). Here it made no difference. Asha's phone has 1.75 pixels for each CSS pixel. 640 × 1.75 is 1,120, and 412 × 1.75 is 721. Either way, only the 1,280-wide file was big enough. Why it matters: always read the HTML your image component writes.
// The photo on the Mint tea page. Times in ms from the start.const ways = [ { way: "img", bytes: 102809, priority: "Medium, then High", arrived: 545.2, lcp: 716 }, { way: "NuxtImg", bytes: 16676, priority: "High", arrived: 469.3, lcp: 524 },];for (const { way, bytes, priority, arrived, lcp } of ways) { console.log(`${way}: ${bytes} bytes, ${priority}, arrived at ${arrived}, LCP ${lcp}`);}- Line 3 is Ben's plain img. Line 4 is NuxtImg. Nothing else differs between the two pages.
- Line 7 prints
img: 102809 bytes, Medium, then High, arrived at 545.2, LCP 716. Then it printsNuxtImg: 16676 bytes, High, arrived at 469.3, LCP 524.
The WebP was about a sixth of the JPEG's size, and High from the start. It arrived before the page's JavaScript started running, and Chrome drew it at once. The JPEG arrived during hydration's 165 ms long task, so it waited: the render delay of lesson 17.2. LCP fell from 716 ms to 524 ms.
One cost: IPX made the WebP on Ben's server, for every request. That took about 71 ms of server time in each visit. The image CDNs of lesson 18.3 make each size once and keep it. Why it matters: on a busy site, put a cache or an image CDN in front of NuxtImg.
Nuxt Fonts: a fallback the size of Lora
Ben loaded Lora with his own rule:
@font-face { font-family: 'Lora'; font-style: normal; font-weight: 400 700; font-display: swap; src: url('/fonts/lora-latin.woff2') format('woff2');}body { font-family: Lora, serif; }- Lines 1 to 7 say where Lora's file is. Line 5,
font-display: swap, shows the text in a fallback font until Lora arrives (lesson 20.1). - Line 8 puts the page's text in Lora, or any serif font until then.
With Nuxt Fonts, Ben deletes lines 1 to 7 and keeps line 8. Nuxt Fonts reads every font-family in the CSS, and finds Lora. Its docs say it then writes the @font-face rules, downloads the files at build time, and serves them from Ben's own site. It also wrote this:
body { font-family: Lora, "Lora Fallback: Times New Roman", "Lora Fallback: Georgia", "Lora Fallback: Noto Serif", "Lora Fallback: Liberation Serif", serif;}@font-face { font-family: "Lora Fallback: Times New Roman"; src: local(Times New Roman), local(Times New Roman Regular), local(TimesNewRoman-Regular), local(TimesNewRomanPSMT); size-adjust: 115.2%; ascent-override: 87.3264%; descent-override: 23.7847%; line-gap-override: 0%;}- Lines 2 to 7 are the body's new font list. After Lora come four fallback fonts that Nuxt Fonts made.
- Lines 9 to 16 are the first one. It uses Times New Roman, a font most computers already have.
- Line 12 makes its letters 115.2% bigger, so its text is as wide as Lora's. Lines 13 to 15 match Lora's line heights. Lesson 20.3 worked numbers like these out by hand.
A theatre's star is late, so an understudy plays the part until the star arrives. If the understudy is much shorter, the costumes don't fit, and the audience sees the swap. If they're the same height, hardly anyone notices.
- In real life: The star
- In CSS: Lora
- In real life: The understudy
- In CSS: Times New Roman, the fallback font
- In real life: An understudy the same height
- In CSS: A fallback with size-adjust and the overrides
- In real life: The audience noticing the swap
- In CSS: The text moving: a layout shift
// Lora on the Mint tea page. lora: when its latin file arrived, in ms.const ways = [ { way: "Ben's @font-face", lora: 706, cls: 0.0062 }, { way: "Nuxt Fonts", lora: 770.4, cls: 0.0002 },];for (const { way, lora, cls } of ways) { console.log(`${way}: Lora at ${lora} ms, CLS ${cls}`);}- Line 3 is the NuxtImg page, with Ben's rule. Line 4 is the same page with Nuxt Fonts.
- Line 7 prints
Ben's @font-face: Lora at 706 ms, CLS 0.0062. Then it printsNuxt Fonts: Lora at 770.4 ms, CLS 0.0002.
Both scores are far below 0.1, the line for a good CLS (lesson 30.1). But the frames show what the number means. With Ben's rule, Whole peppermint wrapped when Lora arrived, and everything below moved down a line. With Nuxt Fonts it had wrapped already, so nothing moved.
Lora came a little later with Nuxt Fonts. That page also downloaded Lora's italic file, for the italic words in the reviews, and the two files shared the line. Google's files are split by alphabet, and Nuxt Fonts' docs say such files aren't preloaded by default. Why it matters: on a page with more text, the same swap moves more lines. A fallback the size of your font takes the jump away.
Vapor Mode: Vue without a virtual DOM
Every page so far used Vue's virtual DOM. On each update, a component's template builds a light copy of its HTML, and Vue compares it with the last copy. That comparison is the work v-memo skips.
Vapor Mode compiles a component without it. Vue's 3.6 release notes call it "a new compilation mode for Vue Single-File Components". It's opt-in, one word on the script tag:
<script setup vapor>import { ref } from 'vue' const count = ref(0)</script>- Line 1 has vapor. The rest of the component is written as before.
The notes say Vapor Mode supports a subset of Vue's features. It has matched Solid and Svelte 5 in third-party benchmarks. An app made only of Vapor components can start with createVaporApp, which leaves out the virtual DOM code. The notes suggest it for one performance-sensitive page of an app, or for small new apps.
Vapor Mode comes with Vue 3.6. This lesson's pages use Vue 3.5.45. Why it matters: when you try it, measure your slowest list before and after, the way this lesson did.
Which Vue or Nuxt tool fixes it?
Read this table across. Each row is one way of the Mint tea page, from the visit with the middle LCP.
| Way | High-priority JavaScript | Long tasks before the scroll | Reviews hydrated | LCP | CLS |
|---|---|---|---|---|---|
| As Ben wrote it | 69.9 kB | 165 ms, 61 ms | With the page | 716 ms | 0.0063 |
| NuxtImg with a preload | 73.3 kB | 170 ms, 57 ms | With the page | 524 ms | 0.0062 |
| Nuxt Fonts | 73.3 kB | 157 ms | With the page | 552 ms | 0.0002 |
| defineAsyncComponent | 73.5 kB | 126 ms | With the page | 548 ms | 0.0002 |
| defineAsyncComponent with hydrateOnVisible | 73.7 kB | None | After the scroll | 552 ms | 0.0002 |
| Lazy, with hydrate-on-visible | 56.0 kB | None | After the scroll | 556 ms | 0.0002 |
Three patterns stand out:
- The photo: NuxtImg's smaller WebP took LCP from 716 ms to 524 ms.
- The font: Nuxt Fonts' fallback took CLS from 0.0062 to 0.0002.
- The start: only the two hydration strategies cleared the long task before the scroll.
Now sort these problems by the tool that fixes them:
- 10,000 products from an API, never changed in place, each wrapped in a proxy
- A chart library's object that Vue keeps wrapping in proxies
- 1,000 rows drawn again when one row becomes selected
- A greeting drawn with the visitor's name that should never change again
- Every remaining row drawn again on each key in a filter box
- Every row component updates when the selected id changes
- 200 reviews far down the page hydrated in one long task at the start
- A chat box far down the page, hydrated at the start though few people open it
- A 1600-pixel JPEG sent to a phone
- The photo at the top asked for at Medium priority
- Text that moves when the web font replaces the fallback
Sort each problem by the Vue or Nuxt tool that fixes it.
Common mix-ups
- "Vue draws the whole page again on every change." No. For Add to cart, it drew only CartBadge, the one component that read the count.
- "A shallowRef makes the list faster to filter." No. On Ben's page the h took 66 ms with a shallowRef and 71.2 ms with a ref. It mostly saved memory.
- "v-memo reuses every row whose values didn't change." No. It compares with the row at the same place last time. After the h, it drew 884 rows again.
- "defineAsyncComponent always loads its code later." No. On a page the server drew, the reviews were hydrated at the start, so their file came at once.
- "hydrateOnVisible waits to download the code." No. Vue's own strategy waits only to hydrate. Nuxt's Lazy prefix also holds the import back.
- "Nuxt Fonts preloads every font." No. Files split by alphabet, like Google's, aren't preloaded unless you ask.
- "Vapor Mode is how Vue works now." No. It's opt-in, and only in Vue 3.6.
Practice exercises
Answer each one first, then open the hints if you need them.
This models v-memo's rule on Ben's list. What does it print?
// The ids of the rows on screen, before and after a filter.
const before = [1, 2, 3, 4, 5];
const after = [1, 3, 4, 5];
// v-memo can reuse a row only if the same review sat at that place before.
const drawn = after.filter((id, place) => before[place] !== id);
console.log(drawn.length);3. Review 2 was hidden, so reviews 3, 4 and 5 each moved up a place. v-memo compares by place, so all three rows are drawn again. Only review 1 kept its place.
Vue compares a row component's props with the last ones. What does it print?
const review = { id: 1, name: "Asha", stars: 5 };
const before = { review, voted: false };
const after = { review: { ...review }, voted: false };
// Vue compares each prop with the last one, like Object.is.
console.log(Object.is(before.review, after.review));false. A copy is a new object. If Ben's list copied each review on every filter, every ReviewRow would get a new review prop, and Vue would draw every row again.
On the v-memo page, how many rows did Vue draw again for the y of honey?
197. After honey, 200 reviews were left. Only 3 of them sat at the same place as after hone, so v-memo reused 3 rows and drew 197 again.
On the Lazy page, how long after Asha's click did the first Helpful button show as pressed, in ms?
13.4 ms. By the time Asha clicked, the reviews had been hydrated for over 2 seconds. Waking them late didn't make the click itself slow.
Open the course's trace of the first reviews page in Chrome's DevTools. It's a development build with app.config.performance on, and holds one click on Helpful. Which entry in the Timings track is the longest?
<App> patch. Patching App includes updating its children: ReviewList's render, with all 1,000 rows and their toHtml calls, then ReviewList's own patch. So App's patch is the widest entry.
Ben wants Lora's latin file preloaded. Which option does he set for the family in Nuxt Fonts?
preload: true. It preloads one upright face near weight 400 in the first subset, such as latin. Expect it to hold the first paint a little, as next/font's preload did in lesson 36.2.
Check your understanding
For each question, ask two things: what did Vue draw or load, and when?
Question 1 of 7Asha clicks Add to cart on any of Ben's reviews pages. Which components does Vue draw again?
Choose an answer to see the explanation.
Question 2 of 7On Ben's first page, why did one Helpful click draw all 1,000 rows again?
Choose an answer to see the explanation.
Question 3 of 7What does a shallowRef track?
Choose an answer to see the explanation.
Question 4 of 7Why did v-memo still draw 884 rows for the h?
Choose an answer to see the explanation.
Question 5 of 7With defineAsyncComponent on the Nuxt page, when did Chrome ask for the reviews' file?
Choose an answer to see the explanation.
Question 6 of 7What did Nuxt Fonts change for Lora on the Mint tea page?
Choose an answer to see the explanation.
Question 7 of 7Can you use Vapor Mode in a stable Vue release?
Choose an answer to see the explanation.
Key takeaways
- Vue draws again only the components whose template read a changed value. It draws each of them whole.
- A ref makes every object inside it reactive. A shallowRef or markRaw saves that memory, for data you replace.
- v-once draws once. v-memo reuses a row whose values didn't change, but only if it stays in the same place.
- A row component with stable props is skipped when the list moves. It costs memory and start time.
- An async component on a server-drawn page still loads at once. Nuxt's Lazy prefix with hydrate-on-visible waits.
- NuxtImg sends smaller files and a preload. Nuxt Fonts adds a fallback sized like your font.
- Vapor Mode drops the virtual DOM, opt-in, in Vue 3.6.
Remember the one-liner.
Vue draws what read a change, whole: keep big templates out of the way, and wake the rest when someone reaches it.
Sources
The facts on this page come from these docs and source files:
- Reactivity in Depth, Vue.
- scheduler.ts, Vue 3.5.45, Vue source.
- Performance, Vue.
- Reactivity API: Advanced (shallowRef, markRaw), Vue.
- ref.ts, Vue 3.5.45, Vue source.
- baseHandlers.ts, Vue 3.5.45, Vue source.
- dep.ts, Vue 3.5.45, Vue source.
- Built-in Directives (v-once, v-memo), Vue.
- vFor.ts, Vue 3.5.45, Vue source.
- renderList.ts, Vue 3.5.45, Vue source.
- componentRenderUtils.ts, Vue 3.5.45, Vue source.
- Async Components, Vue.
- apiAsyncComponent.ts, Vue 3.5.45, Vue source.
- Components: dynamic imports and lazy hydration, Nuxt.
- loader.ts, Nuxt 4.6.4, Nuxt source.
- lazy-hydrated-component.ts, Nuxt 4.6.4, Nuxt source.
- Nuxt performance, Nuxt.
- NuxtImg, Nuxt Image.
- Configuration: screens, Nuxt Image.
- image.ts, Nuxt Image 2.2.1, Nuxt Image source.
- NuxtImg.vue, Nuxt Image 2.2.1, Nuxt Image source.
- How it works, Nuxt Fonts.
- Configuration, Nuxt Fonts.
- Vue 3.6.0-rc.1 release notes: About Vapor Mode, Vue.
- Application API: app.config.performance, Vue.
- profiling.ts, Vue 3.5.45, Vue source.
Coming next: Svelte, Astro, and Qwik. Compiled components, islands and resumability: three ways to send less JavaScript.