Guide
Resuming
The browser does not run view code to start the page. The server sends the HTML, the model and a small listener. A click loads the handler it names and the binding chunks of the model paths that changed. The sizes on this page come from the site's build of examples/todo: pnpm --filter website build measures them into website/dist/demo-server/demo.json. Raw is the size as served, and gzip is zlib level 9 of the same bytes. The build fills the numbers, so a change to the loader or the compiler changes them with no edit here.
#What the server sends
The server render of idlip/server writes plain markup with data attributes. The second todo of the app from Getting started renders as follows, with line breaks added:
<li i-a="4">
<input type="checkbox" on:click="$e3" i-a="5" />
<!--t6-->Write a component<!--/t-->
</li>
on:clicknames an event function,$e3. The manifest lists it with its chunk and the handlers it sends. When the chunk loads, the function reads the row from the model and returns the message["toggle",["a2"]].i-aand the<!--t6-->comments mark the places that bindings patch. A bound text that is the only child of its element has no comments: the element'si-aholds its id, as in<span i-a="3">Ada</span>.- The state script,
<script i-state>at the end of the body, holds the model, the props and the manifest. The manifest lists each handler, its chunk and the model paths it writes.
The <head> holds two scripts:
- The listener from
renderListener(), inline. It listens for the event types of the page and queues each event. It is 1684 B, or 978 B with gzip, counting the script text without its<script>tags. - The loader,
idlip/client, one module script. It starts at the first event.
#Before the first event
The page loads the document and the loader, and nothing else. The state is not decoded yet.
| Request | Raw | gzip |
|---|---|---|
GET / (document) |
5099 B | 2136 B |
GET /assets/loader.<hash>.js |
10086 B | 4030 B |
| Total | 15185 B | 6166 B |
The e2e test records every request from the navigation on, and fails if any other request appears. Moving the pointer and focusing an element are not handled events and load nothing.
#The first click
A click on the second checkbox runs these steps:
- The listener reads
$e3from the checkbox and queues the event with the element. It sends no message yet. - The loader decodes the state script, once for the page.
- The loader imports the
togglehandler chunk, and with it the helpers module the chunks share. The chunk exports the function$e3of the click, which reads the row the user clicked and returns the messagetoggle("a2"). The loader runs the handler on the model. The result is the next model. - The manifest says
togglewritestodos.*.done. The loader imports the binding chunk of that path only. It asks for all three files before any arrives, so the click costs one round trip. - The binding chunk patches the checkbox, the
doneclass of the row and the0 leftcount, sincecountLeft(todos)readstodos.*.done.
todos.*.done, and the binding of that path changes the row and the count.The click makes three requests:
| Request | Raw | gzip |
|---|---|---|
GET /assets/todo.handler.toggle.<hash>.js |
264 B | 213 B |
GET /assets/_idlip-helpers.<hash>.js |
2877 B | 1361 B |
GET /assets/todo.binding.todos._.done.<hash>.js |
469 B | 289 B |
| Total | 3610 B | 1863 B |
A built chunk file is named <module>.<kind>.<name>.<hash>.js, and a _ segment stands for * in the path. _idlip-helpers.<hash>.js holds the DOM and render helpers every chunk of the build imports. It loads once, with the first chunks. The bindings of todos.*.text, todos.*.id and draft, the list chunk and the other three handlers stay on the server.
A second click on any checkbox loads nothing. The chunks are already in the page, and the state was decoded once.
#Write sets
The compiler reads each handler and lists the model paths it writes. The loader loads the binding chunks of those paths. For the todo app:
| Handler | Writes | Binding chunks loaded |
|---|---|---|
setDraft |
draft |
draft |
clear |
draft |
draft |
toggle |
todos.*.done |
todos.*.done |
add |
todos, next, draft |
todos.*.done, todos.*.id, todos.*.text, draft |
toggle maps over todos and changes only done, so its write set is todos.*.done and not all of todos.
#A click before the scripts load
The listener is inline in <head>, so it runs before the loader arrives. A click while the loader is still on the network goes into the queue. When the loader starts, it runs the queued messages in order. The e2e test holds every script request, clicks, and then checks that the page updates once the scripts load.
#Preload the first click
The first click waits for one round trip to fetch its chunks. renderToResponse writes <link rel="modulepreload"> tags for the chunks of the first click. The same tags come from renderPreload(page.chunks, page.manifests) from idlip/server, with the result of render, which returns <link rel="modulepreload"> tags for the chunks of the first click, so the browser fetches them with the page. For the todo page it names the shared helpers module, the toggle handler and the todos.*.done binding.
- Opt-in.
examples/todocalls it, and?preload=offleaves the links out. The counts above are without it. - With it on, the first click makes no request, and the page makes three more requests at load.
format: 'header'returns aLinkheader value instead, for a 103 Early Hints response.