Apps

Live data

A site can read from a web service in the visitor's browser: a list of rows, a form that saves, a sign-in. Every page is still its own static HTML file, but a page with live parts is not complete without its scripts: with scripts off a live list has no rows (the build holds a template and no rows), a live form has no action and sends nothing, a framed island is a blank frame at its reserved height, and an in-page island keeps its fallback. The parts below are opt-in, loaded only on a page that has a live node, and each has a stated limit.

The sample application in

packages/tools/__browser__/fixtures/app

uses all of this and is the one end-to-end test (⁠cuj6.spec.ts⁠).

The pieces

In site.json⁠:

  • backends⁠: the web services pages may call, { name, url, reports? }⁠. A url is https://host[:port][/base] or http://localhost[:port]⁠; no user name, query or fragment.

  • values⁠: named state that outlives a page view, { name, type, initial, keep, secret? }⁠.

  • liveSources⁠: a request a page may make, { name, backend, path, method?, cookies? }⁠. path starts with / and is literal. method is GET (the default) or POST⁠.

  • navigation: "swap"⁠: pages change in place (below).

On a node, live: { source, load, send?, rows?, then?, else? }⁠:

  • load⁠: view (when the page loads), enter-view (when the node scrolls near), trigger (when a trigger says { "load": "<node>" }⁠), submit (when its form is submitted), or { "every": seconds }⁠.

  • send⁠: what the request carries, by name: { "value": "q" } (a site value), { "field": "email" } (a form field read when the request is sent) or { "text": … } (a fixed text or number).

  • rows⁠: the name of the key in the reply that holds the list. With none, the reply itself must be a list.

  • then and else⁠: replies, below.

A node with repeat and live is a live list. A form field takes key (the name a live form sends) and input (⁠text⁠, email⁠, password⁠, search⁠, number⁠).

Decisions of the grammar

These are fixed. Each one is a limit on what a site can say.

  • Where send goes. In the query string for GET⁠, in a JSON body for POST⁠. A request is never sent as a form encoding.

  • field only on a form. A { field } entry is allowed only on a form node (the live setting sits on the form itself), and is read from the field whose key it names when the request is sent.

  • No password in a GET⁠. A { field } that names a password field on a GET source is refused at validation (⁠POLICY_VIOLATION⁠), so a password cannot land in a URL, a log or a history. Use a POST source.

  • A live list supports repeat.max only. filter⁠, exclude⁠, sort⁠, group⁠, skip and a nested repeat on a live list are refused (⁠UNSUPPORTED_CAPABILITY⁠): the backend does these through send⁠. repeat.source still names a data source, which gives the field names the bindings are checked against and the sample rows an editor shows. A list also stops at the smaller of repeat.max and an equal share of the 2,000-element page ceiling.

  • Replies run in the order listed, and goTo runs last. A reply is one of { store, field } (keep a field of the answer in a value), { clear } (clear a value), { show, is } (set a state) and { goTo } (go to a named page of the site). There is at most one goTo per list, and it is not an address: it names a page, and a page that is off or has no safe address has no entry, so the script does nothing for it.

  • What an error is. A network error, a status outside 200 to 299, a body that is not JSON, or a rows that is not a list sets the node's state to error and runs else⁠. An HTML answer is an error and none of it enters the page.

  • Superseded replies are dropped. Each node keeps a request counter. A new request aborts the one in flight, and a reply whose counter is not the latest is ignored.

  • A value change reloads once, after 300 ms. A live node reloads when a value named in its send changes, 300 ms after the last change. A form does not: it waits for its own submit.

  • every is in seconds, at least 5. Validation refuses less. A timer stops when its node leaves the document.

  • { value, by } never goes below 0.

  • No build-time rows. A live source has no rows at build time (files only): the built page holds a template and the loading appearance. Measure never calls a backend; a live node is measured in its loading appearance and an island as its fallback.

A live node holds the reserved state live with values loading⁠, ready⁠, empty⁠, error⁠. A when layer reads it like any state. Two things about it that a site should know:

  • A submit or trigger node starts at loading and stays there until it is used. Nothing runs it at view, so a when layer on live: loading shows on a form from first paint. Do not use loading to mean "a request is in flight" on those nodes.

  • An every reload sets loading again each time, so a when layer on loading flashes on each interval.

Values and their three lifetimes

keep says how long a value lives:

  • view⁠: in the page's memory. It survives an in-place page change, and is gone on a reload or a new visit.

  • tab⁠: in sessionStorage⁠. It survives a reload and is gone when the tab closes.

  • visits⁠: in localStorage⁠. It survives visits.

A value is text⁠, number or boolean⁠. A read of the value on the page is mirrored on <html data-v-<name>>⁠; a secret is mirrored only as set or unset⁠. A when layer reads a site value as { state: "site.<name>", is }⁠.

The key (a secret value)

secret: { backend } marks a value as a key. Its rules:

  • A secret is view or tab⁠, and never visits⁠. Validation refuses visits⁠, so a key does not stay in localStorage between visits. A secret is text.

  • Authorization: Bearer <value> goes only to its own backend, and to nothing else: not to another backend, not to a frame, not in a query. Its initial is never written into the page.

  • The password is never stored. A password field's text is read when the request is sent, never written to a value or storage, and a live form clears its own password fields after any reply, an error included. A trigger that would copy a password field into a value is refused.

  • cookies: true on a source sends cookies with credentials: "same-origin"⁠: for a backend on another origin the browser sends none. Without it, no credentials are sent.

  • Whatever holds the key can use it. In-page code can read it. See islands.md.

Marking a value secret, or changing where it is sent, is a person's decision: the default guard of the MCP server refuses it (see mcp.md).

What this does not protect

  • A page marked "signed-in only" is still a public file. A when layer that shows content only when site.token is set hides it with CSS. Every byte of it is in the HTML that anyone can request. Hiding is not access control. Put private data in the backend's replies, and make the backend check the key.

  • Rows are text. They are written with textContent⁠, never as HTML. A link in a row is used only if it is http:⁠, https: or mailto: after it is resolved against the page (so javascript: and its disguised spellings get no href⁠), and an image only if http: or https:⁠.

  • The policy does not restrict where a link goes (policy.md).

  • A live form never posts natively. It has no address, method="dialog" (a native submit does nothing; Firefox before 98 does not know dialog and may navigate to the same page with no field values), no static form id and no name on its fields, so with scripts off, or before the live script has run, nothing a visitor typed is sent anywhere. The script reads the fields by their key⁠.

  • The honeypot is not a defence. A form carries a hidden website field; a filled one sends nothing. It stops a form-filling bot and nothing else.

  • A live request is limited by the browser, not by Culm. There is no rate limit and no retry. every is the only repeat.

Browser floor

The scripts are built for ES2017. The live script also uses Object.hasOwn (own-property reads of replies, so a key like __proto__ is never a lookup), which sets its floor at Chrome 93, Safari 15.4 and Firefox 92. The islands script uses import() and three observers; their floors were not measured. What a browser below the floor does with a page was not tested. All of it was run in Chromium only.

Changing pages in place

With navigation: "swap"⁠, a click on a link to another page of the site fetches that page and puts its content in place of the current one. Every page is still its own file; with scripts off the links are ordinary links. Values survive (they are held by the live script, which is not run again). The page's own content is replaced, so text typed into a field is not kept.

It is taken over only when all of these hold; otherwise the browser does an ordinary load:

  • The link is on the same origin, no modifier key is down, the button is the main one, target is not another window, and it is not a download.

  • The fetched page answers 200 as HTML, ends on this origin (a redirect from /about to /about/ is followed), and is marked as swappable. A page with a timeline, a GPU effect or a tool table (actions.md) is not.

  • Every _culm/ script of the fetched page is already loaded on this page. A swap never adds a script. So to move from a page to a page that draws an island, the page you leave has to load that island's module too. The sample application draws the chart on each of its three live pages for this reason.

  • The fetched page carries the same policy text. A page of another build, after a redeploy, has other hashes; the visitor gets a full load (policy.md).

The back button swaps too. A view transition is used where the browser has one, unless the visitor asked for reduced motion.

Cost: the navigation script is 2,318 bytes, held to 2,500.

Bytes

A page pays for these scripts only when it uses them. Raw minified UTF-8 bytes, measured from the build:

Script

Bytes

Ceiling

Script

live

Bytes

5,026

Ceiling

6,000

Script

navigation

Bytes

2,318

Ceiling

2,500

Script

islands (+broker)

Bytes

2,719

Ceiling

3,500

Script

a frame's runtime

Bytes

714

Ceiling

-

The three scripts, the frame runtimes and the island modules a page loads count together against appScripts⁠, 12,000. A page with live, navigation, islands and one frame is 10,777 before any module; each further frame adds 714 and its module. In the sample application the sign-in page, which has one frame and one in-page chart, is 11,698 by the build's own page figures (5,026 + 2,318 + 2,719 + 921 for the two modules + 714), 302 under the ceiling; the items and account pages are 10,714.

A plug-in's tool script (⁠_culm/agent.js⁠, actions.md) has its own ceiling, toolScript⁠, 3,000 bytes, outside appScripts⁠. A page with tools also has two fewer elements of room for live rows under the 2,000-element ceiling: one for the tool table and one for the tool script's tag.

Edit this page on GitHub