completefrontend
Open lab My progress
THE WEB PERFORMANCE FIELD GUIDE

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.

By the end, you can
  • 01
    Read what Svelte compilesSee how a component becomes code that updates one text or one attribute, and why a click redrew no rows.
  • 02
    Choose 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.
  • 03
    Compare 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:

Real frames of Ana's Mint tea page, three ways, just after Asha's first tap on 50 g. Each shows 50 g pressed and £2.50. Astro: 15.2 kB of JavaScript at the start, new price 5.2 ms after the tap. Qwik: 44.9 kB of JavaScript at the start, new price 26 ms after the tap. Qwik, preloader off: 22.0 kB of JavaScript at the start, new price 362.8 ms after the tap.AstroAstro: the Mint tea page with 50 g pressed and the price £2.50 for 50 g15.2 kB at the startNew price: 5.2 msQwikQwik: the Mint tea page with 50 g pressed and the price £2.50 for 50 g44.9 kB at the startNew price: 26 msQwik, preloader offQwik, preloader off: the Mint tea page with 50 g pressed and the price £2.50 for 50 g22.0 kB at the startNew price: 362.8 ms
Real frames from the course's recording, just after each page showed the new price. They look the same. Below each: the JavaScript Asha's phone downloaded before the tap, and how long the tap took.

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:

Asha's first tap, on three Mint tea pagesPop out in the code editor (opens in a new tab)JavaScript
// 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 tap first. 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.

Real-life analogyThree ways to pack for a trip

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
The main idea

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 build writes, 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:

CartBadge.svelteSvelte
<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 }). $state is 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:

CartBadge.svelte, as Svelte's compiler wrote itJavaScript
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_effect runs it now, and again whenever cart.count changes. set_text writes 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.

Real-life analogyA café's menu board with slots

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:

One review row in ReviewList.svelteSvelte
<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:

The row, as Svelte's compiler wrote it (a part of the file)JavaScript
$.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:

Ben's Vue page and Ana's Svelte pagePop out in the code editor (opens in a new tab)JavaScript
// 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 prints Svelte: 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:

Playground: each input on Ana's Svelte reviews page
Helpful, on the Svelte page
  1. Time to the next paint, middle of five26.3 ms
  2. The five visits29.1, 27, 26.3, 20.4, 24.9 ms
  3. Main thread working, middle of five18.2 ms
  4. Review rows drawn again0
  5. Kept visit: waiting, handlers, next frame0.8 ms, 12.6 ms, 7 ms
Try it yourself
Helpful: what Svelte did

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.

From the course's recording in Chrome 157, with the CPU slowed 4 times. Times are the middle of 5 visits; the last row is the visit the lesson keeps. Rows drawn come from the counting build, and were the same in every visit.

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:

The top of index.astroAstro
---
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:

The three components with a directive, from index.astroAstro
<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:load loads and hydrates its code "immediately on page load", the docs say.
  • Line 5 is the reviews. client:visible waits 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:

The reviews' island in the built HTML, one attribute per lineHTML
<astro-island  uid="Z9eC2o"  component-url="/_astro/ShopReviews.CfZHdypT.js"  component-export="default"  renderer-url="/_astro/client.BDeQP5SW.js"  props="{}"  ssr  client="visible"  opts="{&quot;name&quot;:&quot;ShopReviews&quot;,&quot;value&quot;: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.

client:load and client:visiblePop out in the code editor (opens in a new tab)JavaScript
// 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 ms first, 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.

CartBadge.astroAstro
---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:

The server island in the built page, shortenedHTML
<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.
Real-life analogyA hotel's welcome letter

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's header in two real frames. At 324.8 ms the badge still says Cart, the fallback. At 398 ms it says Cart (2). Below, to scale: the HTML arrived by 178 ms, the badge's own request ran from 184.7 ms to 357.7 ms, the page first painted at 280 ms, and Cart (2) was on the page at 377.7 ms.324.8 ms: the fallbackThe shop's header, with the cart link saying Cart398 ms: the server islandThe shop's header, with the cart link saying Cart (2)HTMLBadge's requestFirst paint, 280 msCart (2) on the page, 377.7 ms
The page painted first, with the fallback. The badge's request started while the HTML was still being read, and Cart (2) replaced the fallback 97.7 ms after the first paint.
When the page and the badge camePop out in the code editor (opens in a new tab)JavaScript
// 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.7 and "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:

The size buttons in buy-box.tsxTSX
{[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. Its onClick$ 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:

The 50 g button in Qwik's HTMLHTML
<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:click names 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.

Real-life analogyPicking up a chess game from a photo

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:

entry.ssr.tsx, with the preloader turned offTSX
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).
Asha's first tap on 50 g on the Qwik page without the preloader. Two real frames: before the tap, 100 g and £4.80; 362.8 ms after it, 50 g and £2.50. Below, to scale from the tap: the handler's file downloaded from 4.3 ms to 172.9 ms; 2 more files from 174.5 ms to 343 ms; the new price at 362.8 ms. With the preloader, the new price came at 26 ms.Before the tapThe Qwik page before the tap: 100 g pressed, £4.80 for 100 g+362.8 msThe Qwik page after the new price: 50 g pressed, £2.50 for 50 gNothing changes on screenTapHandler's file2 more filesPreloader onnew price at 26 msPreloader off: new price at 362.8 ms
Without the preloader, the tap waited for two trips across the network: the handler's file, then the 2 files it needed. Only then did the price change. With the preloader, the files were already there.
The Qwik page, with and without the preloaderPop out in the code editor (opens in a new tab)JavaScript
// 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:

Playground: four Mint tea pages
Astro: client:load: Asha's visit
  1. JavaScript before the first tap33.4 kB in 5 files
  2. Main thread working before the tap422.7 ms
  3. Of that, Chrome laying out the page146.1 ms
  4. Long tasks before the tap55 ms, 91 ms
  5. The cart badgeCart (2) at 380.8 ms; first paint at 276 ms
  6. 50 g: the new price after5.4 ms
  7. Files downloaded after that tapnone
  8. The reviews' codeasked for at 336 ms, and hydrated at load
  9. Helpful: pressed after16.2 ms
  10. INP's time for the Helpful tap24.2 ms
Try it yourself
Astro: client:load: Svelte islands; the reviews with client:load; Asha's badge as a server island

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.

From the course's recording in Chrome 157, with the CPU slowed 4 times on an imitated Fast 4G line: times in ms after Asha asked for the page, or after her tap, from the visit with the middle first tap of 5. JavaScript is what went over the network, compressed.

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:

The reviews page, from lessons 36.1 to 36.5
Page (lesson)JavaScript, compressedThe h: middle (range of five)Helpful: middle of fiveWhat was different
React, as first written (36.1)113.6 kB97.3 ms (93.5 to 102)Not recordedBundled with names kept. No network line. Helpful wasn't clicked.
Angular, as first written (36.3)71.2 kB82.5 ms (78.3 to 84.9)Not recordedHelpful wasn't clicked.
Angular, with signals (36.3)59.0 kB64.2 ms (62.4 to 65.9)Not recordedTuned after it was first written. Helpful wasn't clicked.
Vue, as first written (36.4)41.4 kB71.2 ms (70.6 to 73.8)44.8 msRecorded the same way as Svelte's.
Vue, row components (36.4)41.5 kB48.8 ms (46.8 to 50.1)17 msTuned after it was first written.
Svelte, as first written (36.5)30.2 kB48.6 ms (45.7 to 52.5)26.3 msThis lesson's page.

Svelte's page looks best on these numbers. But look again, the way you'd test two kettles.

Real-life analogyTesting two kettles fairly

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 h on the reviews page, five visits each, drawn to scale from 40 to 105 ms. React (36.1): from 93.5 to 102 ms, middle 97.3 ms. Angular (36.3): from 78.3 to 84.9 ms, middle 82.5 ms. Angular signals (36.3): from 62.4 to 65.9 ms, middle 64.2 ms. Vue (36.4): from 70.6 to 73.8 ms, middle 71.2 ms. Vue rows (36.4): from 46.8 to 50.1 ms, middle 48.8 ms. Svelte (36.5): from 45.7 to 52.5 ms, middle 48.6 ms.React (36.1)97.3Angular (36.3)82.5Angular signals (36.3)64.2Vue (36.4)71.2Vue rows (36.4)48.8Svelte (36.5)48.650 ms70 ms90 ms
Each bar runs from a page's fastest h to its slowest, over five visits. The dark mark is the middle one. Svelte's bar overlaps Vue's row components, so these runs can't tell those two apart.

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:

Playground: can these runs tell two pages apart?
The h, five visits each
  1. Svelte, as first written: five visits52.5, 52.2, 45.7, 48.6, 48.5 ms
  2. Svelte, as first written: fastest to slowest45.7 to 52.5 ms, middle 48.6 ms
  3. Vue, as first written: five visits71.2, 71, 70.6, 73.8, 71.3 ms
  4. Vue, as first written: fastest to slowest70.6 to 73.8 ms, middle 71.2 ms
  5. What the runs can sayNo overlap: all five Svelte visits were faster. On this page and this laptop, the difference is real.
Try it yourself
Svelte and Vue, as first written

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.

From lessons 36.1 to 36.5's recordings, on the same laptop, in Chrome 157, with the CPU slowed 4 times. Each time is one visit's h, from the key press to the next paint.

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.

Six ways to send less JavaScript
WayWhat it sends at the startWhen its code runsWhat to watch
Svelte's compiled componentsIts 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:loadThe 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:visibleNothing 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:deferA fallback and a small script.On the server, in its own request.The personal part comes one request later.
Qwik with its preloaderThe 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 preloaderThe 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:

What fixes it?
  • 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
Try it yourself
0 of 8 correct

Sort each problem by the way that fixes it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Common mix-ups

  • "Svelte has no runtime." No. The compiled code calls Svelte's runtime, like $.template_effect and $.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.

Exercise 1 · Warm-upRows by key

This models Svelte's keyed each block when Asha deletes the y of honey. What does it print?

Starter codePop out in the code editor (opens in a new tab)JavaScript
// 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);

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upRead a QRL

    This reads the 50 g button's attribute the way the Qwikloader does. What does it print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    // 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}`);

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeThe reviews' island after the scroll

      On the client:visible page, how long after the scroll had the reviews' island finished hydrating, in ms?

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeThe slowest key after h

        On Ana's Svelte page, which key after the h took the longest to the next paint?

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeThe first file after Helpful

          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?

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeState that isn't deep

            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?

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask two things: which code runs, and when?

              The Svelte, Astro, and Qwik quiz · 7 questionsScore: first tries count
              1. Question 1 of 7What does Svelte's compiler turn a component into?

                Choose an answer to see the explanation.

              2. 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.

              3. Question 3 of 7With client:visible, when does Astro download the reviews island's code?

                Choose an answer to see the explanation.

              4. Question 4 of 7What does Asha see in the header before her server island arrives?

                Choose an answer to see the explanation.

              5. 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.

              6. 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.

              7. 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:

              Coming next: CMS and e-commerce platforms. Speed on WordPress, Shopify and similar platforms, where you don't control everything.

              CompleteFrontend Clear concepts. Working examples.