Svelte, Astro, and Qwik
Measure how Svelte's compiled components, Astro's client and server islands, and Qwik's resumability send less JavaScript, and compare frameworks fairly.
- 01Read what Svelte compilesSee how a component becomes code that updates one text or one attribute, and why a click redrew no rows.
- 02Choose islands and resumabilityPick client:load, client:visible or server:defer in Astro, and know what Qwik's first tap costs with and without its preloader.
- 03Compare frameworks fairlyLine up pages built and measured the same way, many times, and know what a small demo can't show.
Ana's three pages that send less JavaScript
Module 36 looks at this course's ideas through each framework's own tools. Lessons 36.1 to 36.4 built Ravi's shop pages in React, Next.js, Angular and Vue. This lesson builds them three more ways.
Ravi's friend Ana likes small pages. She rebuilt his two pages with three frameworks. Each one promises to send less JavaScript. Svelte does it with a compiler. Astro does it with islands. Qwik does it by not hydrating at all.
Asha opens Ana's Mint tea page on her phone. It's the page from lesson 36.4, built three ways. Each time, Asha waits three seconds. Then she taps 50 g, and the price should change to £2.50. Here is her screen just after each tap:
The three pages look the same. But they didn't send the same JavaScript, and they didn't answer at the same speed. The course timed each one:
// Ana's Mint tea page, three ways. kB: the JavaScript Asha's phone// downloaded before her first tap, compressed. tap: ms from her tap on// 50 g until the new price was on the page, the middle of five visits.const pages = [ { page: "Astro", kB: 15.2, tap: 5.2 }, { page: "Qwik", kB: 44.9, tap: 26 }, { page: "Qwik, preloader off", kB: 22, tap: 362.8 },];for (const { page, kB, tap } of pages) { console.log(`${page}: ${kB} kB, new price ${tap} ms after the tap`);}- Lines 1 to 3 are comments. A kB is 1,000 bytes. A millisecond (ms) is a thousandth of a second. Compressed means gzipped, as it travels.
- Lines 5 to 7 hold each page: the JavaScript before the tap, and how long the tap took to show the new price.
- Line 5 is the Astro page, which keeps the reviews' code until they're seen. Lines 6 and 7 are Qwik, with and without its preloader.
- Line 10 prints
Astro: 15.2 kB, new price 5.2 ms after the tapfirst. Then it prints one line for each Qwik page.
Look at line 7. That Qwik page sent only 22.0 kB at the start, less than the other Qwik page. Yet its tap took 362.8 ms. That's about 70 times longer than Astro's. So less JavaScript isn't the whole story. What matters is which code comes, and when it runs. Why it matters: before you pick a framework for its size, ask when its code arrives and when it runs.
Three friends pack for the same trip. One packs a small kit made for this trip only. One packs only for the plans, and leaves the rest at home. The third packs almost nothing. She buys things at the destination when she needs them. Her bag is the lightest. But the first time she needs a towel, she walks to a shop.
- In real life: A kit made for this trip only
- In JavaScript: Svelte: the compiler writes only the code each component needs
- In real life: Packing only for the plans, and nothing else
- In JavaScript: Astro: code only for the parts marked as islands
- In real life: Buying things at the destination when needed
- In JavaScript: Qwik: each handler's code loads when it's first used
- In real life: The walk to the shop the first time
- In JavaScript: The first tap's wait for code
Svelte compiles each component into the exact updates it needs. Astro sends code only for the islands you mark, when you ask. Qwik sends almost nothing at the start, and loads each handler when it's used. Each one moves work, not only bytes. So compare them by when the work happens, on the same page, measured the same way.
How the course recorded it
- Ana's pages: Svelte 5.57.3, built with Vite's production build. Astro 7.4.12, built with
astro build. Qwik 1.20.4, built with its static adapter, which writes each page as an HTML file. - Two pages: lesson 36.1's reviews page, drawn in the browser by Svelte. And lesson 36.4's Mint tea page, in Astro two ways and in Qwik two ways. All four have 36.4's photo, its Lora font and its 200 reviews.
- 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.
- Servers: the Astro pages ran on the Node server that
astro buildwrites, which also draws the badge. The other pages were plain files. Only one server ran at a time. - Real input: mouse clicks and key presses, sent through Chrome's DevTools protocol. The scroll to the reviews was done by a script.
- Counting: the reviews page was built a second time, counting each review row drawn. The counts were the same in every visit.
- 5 visits: each page and way, taking turns. The lesson quotes the middle one.
Svelte compiles each component into small updates
Start with the reviews page from lessons 36.1 to 36.4. It has the cart badge, Add to cart, a box that filters, and 1,000 reviews. Each review has a Helpful button. Here is Ana's cart badge in Svelte:
<script> import { cart } from '../cart.svelte.js'</script> <a id="cart" href="#">Cart ({cart.count})</a>- Line 2 imports the cart. Ana made it with
$state({ count: 0 }).$stateis a rune: a word starting with$that the Svelte compiler reads. It makes reactive state, which Svelte watches for changes. - Line 5 is the badge's HTML. It shows the count in braces.
Svelte uses a compiler: a tool that turns your code into other code before the browser sees it. Its docs say it turns components into "lean, tightly optimized JavaScript". Here is what Svelte 5.57.3 made from those five lines:
import 'svelte/internal/disclose-version';import * as $ from 'svelte/internal/client';import { cart } from '../cart.svelte.js'; var root = $.from_html(`<a id="cart" href="#"> </a>`); export default function CartBadge($$anchor, $$props) { $.push($$props, true); var a = root(); var text = $.only_child(a); $.template_effect(() => $.set_text(text, `Cart (${cart.count ?? ''})`)); $.append($$anchor, a); $.pop();}- Lines 1 and 2 import Svelte's runtime: the small library that compiled code calls. It ships with the page.
- Line 5 holds the badge's HTML. The browser builds it once, by copying this template.
- Lines 10 and 11 find the link, then the text inside it.
- Line 13 is the badge's only update.
template_effectruns it now, and again whenevercart.countchanges.set_textwrites the new words into that one text.
Compare it with lesson 36.4. Vue ran the badge's whole template again, then compared the result with the last one. Svelte's compiler already knows which part can change. So an update is one step: write this text here.
A café paints its menu on a board once. Each price sits in a small slot, on a card. When the price of mint tea changes, someone swaps one card. Nobody repaints the board, or reads all of it to find what changed.
- In real life: The board, painted once
- In Svelte: The template, copied once (line 5)
- In real life: A slot for each price
- In Svelte: One small update for each part that can change
- In real life: Swapping one card
- In Svelte: set_text or set_attribute on one part of the page
- In real life: Repainting the board to compare
- In Svelte: Running a whole template again, as Vue's virtual DOM does
One Helpful click, one attribute
Now the rows. Here is one review row, as Ana wrote it in ReviewList.svelte:
<li class="review"> <h3 class="review-name">{review.name}</h3> <p class="review-date">{review.date}</p> <ReviewStars count={review.stars} /> <div class="review-text">{@html toHtml(review.text)}</div> <button class="helpful" type="button" aria-pressed={votes.includes(review.id)} onclick={() => onhelpful(review.id)} > Helpful </button></li>- Line 5 turns the review's Markdown into HTML with toHtml. toHtml calls marked, the library from lesson 36.1.
- Line 9 fills in the Helpful button from
votes, the list of reviews marked Helpful.
And here is the row's part of the compiled list:
$.html(div, () => toHtml($.get(review).text), true);$.reset(div); var button = $.sibling(div, 2); $.reset(li); $.template_effect( ($0) => { $.set_text(text_2, $.get(review).name); $.set_text(text_3, $.get(review).date); $.set_attribute(button, 'aria-pressed', $0); }, [() => $$props.votes.includes($.get(review).id)]); $.delegated('click', button, () => $$props.onhelpful($.get(review).id));- Line 1 sets the review's HTML. It is an update of its own, and it reads only the review's text. Helpful never runs it.
- Lines 8 to 15 are the row's other update: its name, its date and its aria-pressed.
- Line 14 keeps
votes.includes(...)apart, as a derived value: a value Svelte works out from other state. When votes changes, Svelte works it out again. It runs lines 9 to 13 only if the answer changed (deriveds.js, lines 394 to 395; runtime.js, lines 161 to 176). - Line 17 hands the click to Svelte's event delegation. Svelte's docs say "a single event listener at the application root" runs the handlers.
So one click on Helpful makes Svelte check votes.includes once in each row: 1,000 small checks. One answer changes, so one button gets a new attribute. No row is drawn again. The course counted it:
// Ravi's reviews page: Vue (lesson 36.4, as first written), then Svelte.// js: compressed bytes. Helpful and h: [rows drawn again, ms to the next// paint], the middle of five visits.const pages = [ { name: "Vue", js: 41383, helpful: [1000, 44.8], h: [900, 71.2] }, { name: "Svelte", js: 30186, helpful: [0, 26.3], h: [0, 48.6] },];for (const { name, js, helpful, h } of pages) { console.log(`${name}: ${js} bytes, Helpful ${helpful[1]} ms (${helpful[0]} rows), h ${h[1]} ms (${h[0]} rows)`);}- Line 5 is Ben's Vue page from lesson 36.4, as he first wrote it. Line 6 is Ana's Svelte page.
- Line 9 prints
Vue: 41383 bytes, Helpful 44.8 ms (1000 rows), h 71.2 ms (900 rows). Then it printsSvelte: 30186 bytes, Helpful 26.3 ms (0 rows), h 48.6 ms (0 rows).
Svelte's page sent 11.2 kB less JavaScript. Its Helpful drew no rows, and took 26.3 ms, not 44.8 ms. The h drew no rows either. A keyed each block, like {#each reviews as review (review.id)}, keeps every row whose key it already has. The h only hid 100 reviews, so Svelte only took rows away. Why it matters: compiled updates make a click's work follow what changed, not the size of the template.
But the h still took 48.6 ms, and the main thread worked 47.8 ms of it. Removing 100 rows is work too. Then Chrome lays out the shorter page and paints it. In the visit the course kept, the handlers took 21.1 ms. Drawing the next frame took 25.5 ms. A compiler can't make that part free.
Pick an input to see what Svelte did for it:
- Time to the next paint, middle of five26.3 ms
- The five visits29.1, 27, 26.3, 20.4, 24.9 ms
- Main thread working, middle of five18.2 ms
- Review rows drawn again0
- Kept visit: waiting, handlers, next frame0.8 ms, 12.6 ms, 7 ms
Pick one of Asha's inputs: two clicks, then the five keys of honey. You see how long it took to the next paint, how long the main thread worked, and how many review rows Svelte drew again.
Astro: islands in a static page
Now the Mint tea page. Lesson 35.1 built islands by hand. Astro builds them for you. An Astro page is drawn to HTML when it's built. Its docs say Astro renders every UI component "to just HTML & CSS, stripping out all client-side JavaScript automatically."
To keep a component's JavaScript, you mark it with a client:* directive: a special attribute that Astro reads when it builds the page. Ana wrote the buy box and the reviews as Svelte components. Here is the top of her page, index.astro:
---
import BuyBox from '../components/BuyBox.svelte'
import CartBadge from '../components/CartBadge.astro'
import ReviewStars from '../components/ReviewStars.svelte'
import ShopReviews from '../components/ShopReviews.svelte'
import { TEA } from '../tea.js'
import '../styles/shop.css'
---- Lines 1 and 8 fence the frontmatter: code that runs when the page is built, never in the browser.
- Lines 2 to 6 import the components and the tea's data. Line 7 brings in the page's rules.
And here are the three components with a directive, from further down the page:
<CartBadge server:defer> <a slot="fallback" id="cart" href="#">Cart</a></CartBadge><BuyBox client:load /><ShopReviews client:visible />- Lines 1 to 3 are the cart badge, in the header. The end of this section explains them.
- Line 4 is the buy box.
client:loadloads and hydrates its code "immediately on page load", the docs say. - Line 5 is the reviews.
client:visiblewaits until they enter the screen.
The stars by the rating have no directive, so they stay plain HTML. Each island becomes a custom element in the built page. Astro adds a small script, inline, that defines it:
<astro-island uid="Z9eC2o" component-url="/_astro/ShopReviews.CfZHdypT.js" component-export="default" renderer-url="/_astro/client.BDeQP5SW.js" props="{}" ssr client="visible" opts="{"name":"ShopReviews","value":true}" await-children>- Line 3 names the island's own code. Line 5 names the renderer: the code that hydrates a Svelte component.
- Line 8 says when:
client="visible".
For client:visible, Astro watches the island with an IntersectionObserver: a browser API that tells you when an element enters the screen. On the first sign, Astro stops watching, loads the code and hydrates (visible.ts, lines 22 to 34). Lesson 35.3's lazy page did the same by hand.
// The Astro page. kB: JavaScript before the first tap, compressed. busy: ms// the main thread worked before the tap. reviewsCode: when Chrome asked for// the reviews' island, in ms. Asha scrolled to the reviews at about 5,200 ms.const ways = [ { way: "client:load", kB: 33.4, busy: 425, reviewsCode: 336 }, { way: "client:visible", kB: 15.2, busy: 332.3, reviewsCode: 5193.5 },];for (const { way, kB, busy, reviewsCode } of ways) { console.log(`${way}: ${kB} kB, busy ${busy} ms, reviews' code asked for at ${reviewsCode} ms`);}- Lines 5 and 6 hold each way: the JavaScript before Asha's tap, how long the main thread worked before it, and when Chrome asked for the reviews' code.
- Line 9 prints
client:load: 33.4 kB, busy 425 ms, reviews' code asked for at 336 msfirst, then the same for client:visible.
client:visible sent less than half the JavaScript before the tap. The reviews' file, 18.2 kB with marked and the reviews' words, came only after Asha scrolled. The main thread also worked 92.7 ms less. On the client:load page, the reviews' hydration showed up as one long task of 91 ms. Why it matters: islands far down the page are the easiest JavaScript to move out of the way.
Notice what didn't change. Both ways still worked over 300 ms before the tap, and most of it wasn't JavaScript. In the client:visible visit the course kept, 151.5 ms of it was Chrome laying out the page's 200 reviews: as the HTML came in, and again when Lora arrived. Every Mint tea page in this lesson paid for that layout.
A server island for Asha's cart badge
Asha has two teas in her cart. A page that says "Cart (2)" is hers alone. If the server drew it into the page, nobody else could get that page from a cache. Astro's server island solves this. Its docs say the page "will be rendered immediately with any specified fallback content". Then the island's own content is fetched, and shown when it arrives.
---const count = Number(Astro.cookies.get('cart')?.value ?? 0)--- <a id="cart" href="#">Cart ({count})</a>- Lines 1 to 3 run on the server, for each visit. Line 2 reads Asha's cart from her cookie.
- Line 5 is the badge.
Back in index.astro, server:defer on line 1 made the badge a server island. Line 2 gave it a fallback: a plain "Cart" link. To draw the island on demand, Astro needs an adapter, a package that runs its server. Ana used Astro's Node adapter. Here is what the built page holds in the badge's place:
<link rel="preload" as="fetch" href="/_server-islands/CartBadge?e=…&p=&s=" crossorigin="anonymous"><a id="cart" href="#">Cart</a><script type="module" data-astro-rerun>const headers = new Headers({});let response = await fetch("/_server-islands/CartBadge?e=…&p=&s=", { headers }).catch(() => {});replaceServerIsland("…", response);</script>- Line 1 sits in the head. It starts the island's request early, while the page is still arriving (server-islands.ts, lines 209 to 216).
- Line 2 is the fallback.
- Lines 3 to 7 are a small script. Line 5 fetches the island from a route Astro made for it. Line 6 swaps the fallback for the answer.
A hotel prints the same welcome letter for every guest, days before they come. It leaves one line blank: "Welcome, ______". When you arrive, the receptionist writes your name in. The letter was ready at once. Only your name waited for you.
- In real life: The printed letter, the same for every guest
- In Astro: The static page, which a cache can keep for everyone
- In real life: The blank line
- In Astro: The fallback: Cart
- In real life: The receptionist writing your name
- In Astro: The server island's own request
- In real life: Your name on the line
- In Astro: Cart (2)
// The Astro page with client:visible: the visit the lesson keeps. Times in ms.const visit = { painted: 280, asked: 184.7, arrived: 357.7, badge: 377.7 };console.log(`First paint, with "Cart": ${visit.painted}`);console.log(`The badge's request: from ${visit.asked} to ${visit.arrived}`);console.log(`"Cart (2)" on the page: ${visit.badge}`);- Line 2 holds the visit's times, in ms after Asha asked for the page.
- Lines 3 to 5 print
First paint, with "Cart": 280,The badge's request: from 184.7 to 357.7and"Cart (2)" on the page: 377.7.
The page painted at 280 ms with "Cart". Asha's badge came 97.7 ms later. Its request started at 184.7 ms, as soon as Chrome read the head. It didn't wait for the page's JavaScript. Why it matters: a personal part no longer holds the page back. The page itself can be cached and sent at once.
Qwik resumes instead of hydrating
Lesson 35.3 wrote a resumable page by hand, after Qwik's idea. Now here is Qwik itself. Its docs say hydration "replays all the application logic on the client." Qwik "pauses execution on the server, and resumes execution on the client." So resumability means the browser carries on from where the server stopped. No component runs at load.
Ana's buy box in Qwik keeps the size in a signal, Qwik's reactive value. Here are its size buttons:
{[50, 100].map((grams) => ( <button key={grams} class="size" type="button" aria-pressed={grams === size.value} onClick$={() => (size.value = grams)}> {grams} g </button>))}- Line 1 makes a button for each size: 50 g and 100 g.
- Line 2 sets aria-pressed from
size.value. ItsonClick$is the handler. Qwik's docs say the$tells its build to move that function "into a separate file".
Here is the 50 g button as Qwik's server wrote it:
<button aria-pressed="false" type="button" class="size" on:click="q-D0GLPys4.js#s_wfibSBscFBU[0 1]" q:key="50" q:id="7">- Line 1 is the whole button. Its
on:clicknames a file and a function in it. Qwik calls this a QRL: a URL to code that can load later. - The
[0 1]at the end points at the two values the handler uses. Qwik wrote them into the page as JSON.
No code is attached to this button. Instead, the Qwikloader, a small script, listens for clicks on the whole document (qwikloader.ts, lines 261 to 263). When a click reaches an element with on:click, it imports that file and calls the function (lines 139 to 145). It's like Svelte's event delegation. But here, the handler's code isn't on the page yet.
Two friends stop a game of chess halfway. To carry on at another table, they could replay every move from the start. Or they could take a photo of the board and set the pieces out from it. Then they play the next move at once. Only if one of them forgets how a piece moves do they need to look it up.
- In real life: Replaying every move from the start
- In Qwik: Hydration: running every component again in the browser
- In real life: The photo of the board
- In Qwik: The HTML, with on:click attributes and the state as JSON
- In real life: Setting out the pieces and playing on
- In Qwik: Resuming: no component runs at load
- In real life: Looking up how a piece moves
- In Qwik: Loading a handler's code on its first tap
The first tap, with and without the preloader
Loading code on a tap has a cost. Qwik's docs say so: it "would create a noticeable delay, especially on slow networks." So Qwik has a preloader. After the page's load event, when the browser is idle, it fetches the handlers' files (preload-impl.ts, lines 163 to 171). It uses <link rel="modulepreload">, so the files are downloaded but not run. Ana built the page twice: as Qwik builds it, and with the preloader turned off:
import { renderToStream, type RenderToStreamOptions } from '@builder.io/qwik/server'import Root from './root' export default function (opts: RenderToStreamOptions) { return renderToStream(<Root />, { ...opts, preloader: false, containerAttributes: { lang: 'en', ...opts.containerAttributes }, })}- Lines 4 to 10 are Qwik's render function, as its starter writes it.
- Line 7 turns the preloader off. Qwik still preloads its own core file either way (preload-impl.ts, lines 86 to 89).
// The Qwik page. kB: JavaScript before the first tap. tap and helpful: ms// until the change was on the page. inp: Event Timing's time for the tap on// Helpful. The middle of five visits.const ways = [ { way: "preloader on", kB: 44.9, tap: 26, helpful: 108.9, inp: 3.1 }, { way: "preloader off", kB: 22, tap: 362.8, helpful: 468.4, inp: 3.9 },];for (const { way, kB, tap, helpful, inp } of ways) { console.log(`${way}: ${kB} kB, 50 g ${tap} ms, Helpful ${helpful} ms (INP said ${inp} ms)`);}- Lines 5 and 6 hold each way.
- Line 9 prints
preloader on: 44.9 kB, 50 g 26 ms, Helpful 108.9 ms (INP said 3.1 ms)first, then the same for the page without the preloader.
Without the preloader, the page sent only 22.0 kB at the start: the Qwikloader and Qwik's core. Then Asha's tap waited 362.8 ms. The picture shows why. The handler's file took one trip across the network, about 169 ms. It needed 2 more files, which took a second trip. Nothing changed on screen until they came. With the preloader, the files were already there, and the price changed in 26 ms. Why it matters: resumability saves the work at load, but the code still has to come from somewhere. Keep the preloader on.
The preloader isn't free either. It fetched 11 files before the tap, 44.9 kB, more than either Astro page. One of them was the reviews' code with marked, 17.8 kB. It was downloaded, but not run.
What INP didn't see
Now look at Helpful on the page with the preloader. The button showed as pressed 108.9 ms after the tap. INP said 3.1 ms. Both are right. INP measures until the next paint after the event's handlers (lesson 26.1). The Qwikloader's handler returned at once, and Chrome painted a frame with nothing new in it.
Qwik's real work came after that frame. It ran the reviews' component again, with marked for each of the 200 reviews. The main thread worked 108.2 ms, and the Long Tasks API reported one task of 83 ms. Why it matters: on a page that loads code after a tap, check when the change is on screen, not only INP.
One more thing. This lesson uses Qwik 1.20.4, the stable release. Qwik 2 moves to new package names, under @qwik.dev.
Pick a page to see all four Mint tea pages side by side:
- JavaScript before the first tap33.4 kB in 5 files
- Main thread working before the tap422.7 ms
- Of that, Chrome laying out the page146.1 ms
- Long tasks before the tap55 ms, 91 ms
- The cart badgeCart (2) at 380.8 ms; first paint at 276 ms
- 50 g: the new price after5.4 ms
- Files downloaded after that tapnone
- The reviews' codeasked for at 336 ms, and hydrated at load
- Helpful: pressed after16.2 ms
- INP's time for the Helpful tap24.2 ms
Pick a page. Asha opened it and waited three seconds. Then she tapped 50 g, scrolled to the reviews, and tapped Helpful on the first one.
Comparing frameworks fairly
It's tempting to end with a ranking. This module recorded the same reviews page in four frameworks, on the same laptop, in Chrome 157. Here are the numbers from each lesson. Read each row across:
| Page (lesson) | JavaScript, compressed | The h: middle (range of five) | Helpful: middle of five | What was different |
|---|---|---|---|---|
| React, as first written (36.1) | 113.6 kB | 97.3 ms (93.5 to 102) | Not recorded | Bundled with names kept. No network line. Helpful wasn't clicked. |
| Angular, as first written (36.3) | 71.2 kB | 82.5 ms (78.3 to 84.9) | Not recorded | Helpful wasn't clicked. |
| Angular, with signals (36.3) | 59.0 kB | 64.2 ms (62.4 to 65.9) | Not recorded | Tuned after it was first written. Helpful wasn't clicked. |
| Vue, as first written (36.4) | 41.4 kB | 71.2 ms (70.6 to 73.8) | 44.8 ms | Recorded the same way as Svelte's. |
| Vue, row components (36.4) | 41.5 kB | 48.8 ms (46.8 to 50.1) | 17 ms | Tuned after it was first written. |
| Svelte, as first written (36.5) | 30.2 kB | 48.6 ms (45.7 to 52.5) | 26.3 ms | This lesson's page. |
Svelte's page looks best on these numbers. But look again, the way you'd test two kettles.
You want to know which of two kettles boils faster. You fill both with the same water, from the same tap. You use the same stove. You boil each one five times, and take the middle time. And you remember that a kettle that's quick for one cup may be slow for a full pot.
- In real life: The same amount of water
- In JavaScript: The same page and the same data
- In real life: The same stove
- In JavaScript: The same laptop, browser, CPU slowdown and network
- In real life: Five boils, and the middle time
- In JavaScript: Five visits: the middle, and the range
- In real life: One cup or a full pot
- In JavaScript: A small demo or a whole app
Now check the table the same way:
- The same page and data. Every page drew the same 1,000 reviews with marked, with the same layout. But "as first written" isn't "tuned". Vue's row-component page took 48.8 ms for the h. Svelte's took 48.6 ms.
- The same device. All six ran on the same laptop, with the CPU four times slower. React's page had no network line, and was cross-origin isolated, which gives it a finer clock. Neither changes a key press after the page has loaded. But say so when you compare.
- The same build mode. All are production builds. But lesson 36.1 bundled React with the names kept, so its trace could name each component. Its 113.6 kB can't be set against the others' fully shrunk files.
- The same inputs. Lessons 36.1 and 36.3 didn't click Helpful on this page. So there's no Helpful time to compare for React or Angular.
- Many runs. One visit can mislead. On the Qwik page with the preloader, LCP was 912 ms in one visit, and 500 ms to 644 ms in the other four. If two pages' ranges overlap, these runs can't say which is faster.
The picture draws each page's five h times. Svelte's ran from 45.7 to 52.5 ms. Vue's row-component page ran from 46.8 to 50.1 ms. The two overlap, so these runs can't say which is faster. Svelte's range doesn't touch Vue's first page, so that difference is real, on this page and this laptop. Why it matters: a gap smaller than the spread between runs isn't a result.
Pick two pages, and see what their runs can say:
- Svelte, as first written: five visits52.5, 52.2, 45.7, 48.6, 48.5 ms
- Svelte, as first written: fastest to slowest45.7 to 52.5 ms, middle 48.6 ms
- Vue, as first written: five visits71.2, 71, 70.6, 73.8, 71.3 ms
- Vue, as first written: fastest to slowest70.6 to 73.8 ms, middle 71.2 ms
- What the runs can sayNo overlap: all five Svelte visits were faster. On this page and this laptop, the difference is real.
Pick two reviews pages. You see the h's time to the next paint in each page's five visits. If the two ranges overlap, the runs can't say which page is faster.
What a small demo can't show
This module's pages are small: one page, one list, a few buttons. A demo like this can't show four things:
- How the JavaScript grows as an app adds pages and features.
- The code your team will really write. It's rarely the tuned version.
- What changes on another device, network or browser.
- Costs that aren't JavaScript. Every framework here paid for the layout of the 200 reviews.
So use a demo to learn how a framework works, as this module did. Then measure your own pages, with your own data, before you choose.
Which one fits which part of a page?
Read this table across. Each row is one way to send less JavaScript, with what this lesson measured.
| Way | What it sends at the start | When its code runs | What to watch |
|---|---|---|---|
| Svelte's compiled components | Its runtime and every component on the page: 30.2 kB for the reviews page. | At load, when it draws the page. | Work that isn't JavaScript, like layout, still counts. |
| Astro with client:load | The island's code and its framework: 33.4 kB here. | At load: it hydrates at once. | A big island still hydrates in a long task. |
| Astro with client:visible | Nothing for that island until it's seen: 15.2 kB here. | When the island scrolls into view. | A tap right after the scroll may wait for the code. |
| Astro with server:defer | A fallback and a small script. | On the server, in its own request. | The personal part comes one request later. |
| Qwik with its preloader | The Qwikloader, its core, then the handlers' files when idle: 44.9 kB here. | When a handler is first used. | INP can miss the work after a tap. |
| Qwik without the preloader | The Qwikloader and its core: 22.0 kB here. | When a handler is first used, after its download. | The first tap waits for the network. |
Now sort these problems by what fixes them:
- One Helpful click runs a 1,000-row template again
- A cart count that should change one text, not a whole component
- A reviews widget far down a static page, hydrated at load
- A size picker people use at once, on an otherwise static page
- Each visitor's cart count, on a page you want a CDN to cache
- A "Hello, Asha" line that makes the whole page different for each visitor
- A huge page whose hydration blocks the first tap for a second
- A first tap that waits for its handler's code on a slow network
Sort each problem by the way that fixes it.
Common mix-ups
- "Svelte has no runtime." No. The compiled code calls Svelte's runtime, like
$.template_effectand$.set_text. It's part of the page's 30.2 kB. - "Astro pages send no JavaScript." No. Each client island sends its own code and its framework. The client:load page sent 33.4 kB before the tap.
- "client:visible leaves the reviews out of the HTML." No. The reviews were in the HTML from the start. Only their code waited for the scroll.
- "A server island makes the page wait for the server." No. The page painted with its fallback first. The badge came 97.7 ms later.
- "Qwik sends no JavaScript at the start." No. Even with the preloader off, the Qwikloader and Qwik's core came at load: 22.0 kB.
- "A low INP means the tap felt fast." No. Qwik's Helpful tap had an INP of 3.1 ms, but the button showed as pressed after 108.9 ms.
- "The page with the least JavaScript is the fastest." No. The Qwik page without the preloader sent less than the one with it. Its first tap was the slowest of all.
Practice exercises
Answer each one first, then open the hints if you need them.
This models Svelte's keyed each block when Asha deletes the y of honey. What does it print?
// The ids of the reviews on screen, before and after Asha deletes the y.
const before = [1, 2, 4];
const after = [1, 2, 3, 4];
// A keyed each block keeps every row whose key it already has.
const drawn = after.filter((id) => !before.includes(id));
console.log(drawn.length);1. A keyed each block matches rows by their key, not their place. Rows 1, 2 and 4 are kept, even though 4 moved. Only review 3 needs a new row, and only it runs toHtml.
This reads the 50 g button's attribute the way the Qwikloader does. What does it print?
// The 50 g button's on:click attribute, from Qwik's HTML.
const qrl = "q-D0GLPys4.js#s_wfibSBscFBU[0 1]";
const [file, rest] = qrl.split("#");
const name = rest.replace(/\[.*$/, "");
console.log(`import("/build/${file}"), then call ${name}`);import("/build/q-D0GLPys4.js"), then call s_wfibSBscFBU. The Qwikloader joins the file to the page's q:base, /build/, imports it, and calls the function with that name.
On the client:visible page, how long after the scroll had the reviews' island finished hydrating, in ms?
280.4 ms. Chrome asked for the reviews' file just after the scroll. It took one trip to arrive, then Svelte hydrated the 200 reviews in a long task.
On Ana's Svelte page, which key after the h took the longest to the next paint?
The o. It hid 550 more reviews: from 900 to 350. Removing rows is work, even when none is drawn again, so the key that removes the most takes longest.
Open the course's trace of the Qwik page without the preloader in Chrome's DevTools. Which JavaScript file did Chrome ask for first after the tap on Helpful?
q-D4vaoK5E.js: the Helpful handler's own file. It took one trip, then Chrome asked for the files it needed, the reviews' code with marked among them.
Ana wants to keep a big list of reviews in state, but only ever replace it whole. Which form of $state skips the deep proxy?
$state.raw. Its docs say raw state can only be reassigned, not changed in place, and that it skips the cost of making big arrays and objects reactive.
Check your understanding
For each question, ask two things: which code runs, and when?
Question 1 of 7What does Svelte's compiler turn a component into?
Choose an answer to see the explanation.
Question 2 of 7On Ana's Svelte reviews page, what did one click on Helpful change in the page?
Choose an answer to see the explanation.
Question 3 of 7With client:visible, when does Astro download the reviews island's code?
Choose an answer to see the explanation.
Question 4 of 7What does Asha see in the header before her server island arrives?
Choose an answer to see the explanation.
Question 5 of 7Without the preloader, why did Qwik's first tap on 50 g wait so long?
Choose an answer to see the explanation.
Question 6 of 7Qwik's Helpful tap had a tiny INP, yet the button showed as pressed much later. Why?
Choose an answer to see the explanation.
Question 7 of 7Why can't lesson 36.1's React bundle size be set against Svelte's?
Choose an answer to see the explanation.
Key takeaways
- Svelte compiles each component into small updates. A Helpful click changed one attribute and drew no rows.
- Astro sends no JavaScript for a component without a client directive. client:visible waits until the island is seen.
- A server island lets the page paint at once with a fallback. The personal part comes in its own request.
- Qwik resumes: no component runs at load. Each handler's code loads on its first use, so keep the preloader on.
- INP stops at the next paint. When code loads after a tap, measure when the change is on screen.
- Compare frameworks on the same page, data, device and build mode, over many runs. A small demo can't show a whole app.
Remember the one-liner.
Less JavaScript is a question of when: what runs at load, what waits, and who pays when it's needed.
Sources
The facts on this page come from these docs and source files:
- Overview, Svelte.
- What are runes?, Svelte.
- $state, Svelte.
- Basic markup: event delegation, Svelte.
- deriveds.js, Svelte 5.57.3, Svelte source.
- runtime.js, Svelte 5.57.3, Svelte source.
- {#each ...}: keyed each blocks, Svelte.
- Islands architecture, Astro.
- Template directives reference, Astro.
- visible.ts, Astro 7.4.12, Astro source.
- Server islands, Astro.
- server-islands.ts, Astro 7.4.12, Astro source.
- Resumable vs. Hydration, Qwik.
- The $ dollar sign, Qwik.
- QRL, Qwik.
- Qwikloader, Qwik.
- qwikloader.ts, Qwik 1.20.4, Qwik source.
- Prefetching Modules, Qwik.
- preload-impl.ts, Qwik 1.20.4, Qwik source.
- Long Tasks API, W3C.
Coming next: CMS and e-commerce platforms. Speed on WordPress, Shopify and similar platforms, where you don't control everything.