web: assets with fingerprints (WEB slice 5) #100

Closed
opened 2026-10-05 21:07:20 +00:00 by orion · 11 comments
Collaborator

Context

assets with List<Resource>, fingerprinted URLs, and the stylesheet/script elements that write them (WEB slice 5).

Source

  • WEB.md slice 5, section 3.7 (static assets), decision D11 (assets before ResourceDirectory), section 4.7 (URL attributes take a Link)
  • docs/design/RESOURCES.md (Resource, Resource.bytes(), ResourceError; slices 1-3 done)

Goal

A web { ... } application can declare assets "/assets", files: [...] over List<Resource> literals. Each file is served at a fingerprinted URL (/assets/site.<hash>.css) with Cache-Control: immutable, and a page links it through stylesheet(...)/script(...) elements that write that URL, so a deploy never leaves a stale link.

Acceptance criteria

  • WebApp gains var fn assets(prefix: String, files: List<Resource>) (one more member of the builder from #777; the vocabulary stays wrap, assets, handle, errors).
  • Fingerprint: the first 8 lowercase hex characters of the SHA-256 of the file's bytes (std/digest, std/encoding hexadecimal), inserted before the last extension (site.css -> site.3f2a9c10.css; no extension -> appended). Computed once, at startup (first use of the app), from Resource.bytes().
  • A request for the fingerprinted path answers 200 with the file's bytes, a Content-Type from the extension (css, js, svg, png, jpg, webp, ico, woff2, json, txt; application/octet-stream otherwise) and Cache-Control: public, max-age=31536000, immutable. The un-fingerprinted path, a stale hash, a path outside the listed files and a .. segment answer 404 (nothing is served that the author did not name). Non-GET/HEAD answers 405.
  • A file that cannot be read at startup is a WebError from the app (tryWeb answers it, web fails at startup as #777 specifies), never a request-time surprise; two files with the same name under one prefix are refused.
  • A value that is a Link names an asset: app.assetLink(file: Resource): Link (or the equivalent accessor on WebApp) returns the fingerprinted URL; std/html gets stylesheet(sheet: Link) and script(source: Link) elements (<link rel="stylesheet" href=...>, <script src=...>) that take a Link, never a String.
  • Tests in std/web/tests/ with WebTest/app.answer: fingerprint stable across two builds of the same bytes and different for different bytes, the 200 headers, each 404/405 case, the link elements' rendered HTML. A conformance program only if a new codegen shape appears.
  • docs/design/WEB.md (slice 5 marked built, 3.7 updated), docs/standard-library/web.md and html.md updated; skills/ regenerated.

Design record points

  • WEB.md 3.7: assets are resources; fingerprint = hash of the bytes at startup; immutable; stylesheet/script take the resource's URL.
  • WEB.md D11 (a): v1 lists files as Resource literals; no Path directory serving and no ResourceDirectory (F8 stays out of scope; this issue does not wait for it).
  • EmbeddedBytes assets (favicon, client script of 6.8) are out of scope here; they belong with the client script (slice 7).

Seed impact

None expected: library code in std/web and std/html only; no syntax change, no new native, no new driver flag, no std name the compiler looks up by string. One commit for the feature, plus an optional second for docs/skills regeneration; no two-commit seed rule applies. If implementation finds a missing hash native, stop and file it separately.

Size

One PR, one or two Conventional Commits: feat(std/web): assets with fingerprinted URLs (+ docs(web): slice 5 built if split).

Dependencies

  • #136 (resources: shipping): closed, Resource.bytes() is available.
  • #94 (std/web core): its step 2 is #776 / PR #777 (Middleware, Next, WebApp, web). Implementation starts once #777 has merged; it builds on std/web/src/app.trb from that PR.

Moved from the planning lists of the docs; the design record stays the specification.

## Context `assets` with `List<Resource>`, fingerprinted URLs, and the `stylesheet`/`script` elements that write them (WEB slice 5). ## Source - [WEB.md slice 5](https://git.torb.dev/torbscript/language/src/commit/393ef2608e4a60b8ff76d8b6b408951b822d887d/docs/design/WEB.md#L978), section 3.7 (static assets), decision D11 (assets before `ResourceDirectory`), section 4.7 (URL attributes take a `Link`) - `docs/design/RESOURCES.md` (`Resource`, `Resource.bytes()`, `ResourceError`; slices 1-3 done) ## Goal A `web { ... }` application can declare `assets "/assets", files: [...]` over `List<Resource>` literals. Each file is served at a fingerprinted URL (`/assets/site.<hash>.css`) with `Cache-Control: immutable`, and a page links it through `stylesheet(...)`/`script(...)` elements that write that URL, so a deploy never leaves a stale link. ## Acceptance criteria - [ ] `WebApp` gains `var fn assets(prefix: String, files: List<Resource>)` (one more member of the builder from #777; the vocabulary stays `wrap`, `assets`, `handle`, `errors`). - [ ] Fingerprint: the first 8 lowercase hex characters of the SHA-256 of the file's bytes (`std/digest`, `std/encoding` hexadecimal), inserted before the last extension (`site.css` -> `site.3f2a9c10.css`; no extension -> appended). Computed once, at startup (first use of the app), from `Resource.bytes()`. - [ ] A request for the fingerprinted path answers 200 with the file's bytes, a `Content-Type` from the extension (css, js, svg, png, jpg, webp, ico, woff2, json, txt; `application/octet-stream` otherwise) and `Cache-Control: public, max-age=31536000, immutable`. The un-fingerprinted path, a stale hash, a path outside the listed files and a `..` segment answer 404 (nothing is served that the author did not name). Non-GET/HEAD answers 405. - [ ] A file that cannot be read at startup is a `WebError` from the app (`tryWeb` answers it, `web` fails at startup as #777 specifies), never a request-time surprise; two files with the same name under one prefix are refused. - [ ] A value that is a `Link` names an asset: `app.assetLink(file: Resource): Link` (or the equivalent accessor on `WebApp`) returns the fingerprinted URL; `std/html` gets `stylesheet(sheet: Link)` and `script(source: Link)` elements (`<link rel="stylesheet" href=...>`, `<script src=...>`) that take a `Link`, never a `String`. - [ ] Tests in `std/web/tests/` with `WebTest`/`app.answer`: fingerprint stable across two builds of the same bytes and different for different bytes, the 200 headers, each 404/405 case, the link elements' rendered HTML. A conformance program only if a new codegen shape appears. - [ ] `docs/design/WEB.md` (slice 5 marked built, 3.7 updated), `docs/standard-library/web.md` and `html.md` updated; `skills/` regenerated. ## Design record points - WEB.md 3.7: assets are resources; fingerprint = hash of the bytes at startup; `immutable`; `stylesheet`/`script` take the resource's URL. - WEB.md D11 (a): v1 lists files as `Resource` literals; no `Path` directory serving and no `ResourceDirectory` (F8 stays out of scope; this issue does not wait for it). - `EmbeddedBytes` assets (favicon, client script of 6.8) are out of scope here; they belong with the client script (slice 7). ## Seed impact None expected: library code in `std/web` and `std/html` only; no syntax change, no new native, no new driver flag, no std name the compiler looks up by string. One commit for the feature, plus an optional second for docs/skills regeneration; no two-commit seed rule applies. If implementation finds a missing hash native, stop and file it separately. ## Size One PR, one or two Conventional Commits: `feat(std/web): assets with fingerprinted URLs` (+ `docs(web): slice 5 built` if split). ## Dependencies - #136 (resources: shipping): closed, `Resource.bytes()` is available. - #94 (std/web core): its step 2 is #776 / PR #777 (`Middleware`, `Next`, `WebApp`, `web`). **Implementation starts once #777 has merged**; it builds on `std/web/src/app.trb` from that PR. _Moved from the planning lists of the docs; the design record stays the specification._
Author
Collaborator

[loop:torbscript] intake: in scope (author orion, label loop). Implements WEB.md slice 5; no collision with a design record. Depends on #94 and #136 (both open). next: waiting on dependencies, then refine.

[loop:torbscript] intake: in scope (author orion, label loop). Implements WEB.md slice 5; no collision with a design record. Depends on #94 and #136 (both open). next: waiting on dependencies, then refine.
Author
Collaborator

[loop:torbscript] wait: refine of WEB slice 5 needs #94 (std/web core, WEB slice 2) landed; #136 is closed. Rechecked 2026-11-14.
next: refine when #94 closes

[loop:torbscript] wait: refine of WEB slice 5 needs #94 (std/web core, WEB slice 2) landed; #136 is closed. Rechecked 2026-11-14. next: refine when #94 closes
Author
Collaborator

[loop:torbscript] claim refine by session:loop-torbscript-20261114 until 2026-11-14T06:00:00Z

[loop:torbscript] claim refine by session:loop-torbscript-20261114 until 2026-11-14T06:00:00Z
Author
Collaborator

[loop:torbscript] decided by the loop: fingerprint = first 8 hex chars of SHA-256 (std/digest) of the bytes, before the last extension, as WEB.md 3.7 shows (site.3f2a9c10.css); no directories (D11 a, F8 out); EmbeddedBytes assets left to slice 7; not seed-affecting (library code only).

[loop:torbscript] refine: issue body rewritten to the definition of ready (goal, 7 testable criteria, design record points, seed impact none, size one PR of 1-2 commits, dependency line). #136 is closed; #94 step 2 is #777, so the implement stage must wait until #777 has merged (builds on its WebApp). Claim 12350 released.
next: implement (ready, after #777 merged)

[loop:torbscript] decided by the loop: fingerprint = first 8 hex chars of SHA-256 (std/digest) of the bytes, before the last extension, as WEB.md 3.7 shows (`site.3f2a9c10.css`); no directories (D11 a, F8 out); EmbeddedBytes assets left to slice 7; not seed-affecting (library code only). [loop:torbscript] refine: issue body rewritten to the definition of ready (goal, 7 testable criteria, design record points, seed impact none, size one PR of 1-2 commits, dependency line). #136 is closed; #94 step 2 is #777, so the implement stage must wait until #777 has merged (builds on its `WebApp`). Claim 12350 released. next: implement (ready, after #777 merged)
Author
Collaborator

[loop:torbscript] wait: implementation needs the web builder and app.answer of #776 (PR #777, CI queued, review pending); the issue stays ready and starts once #777 has merged. next: waiting (dependency #776)

[loop:torbscript] wait: implementation needs the `web` builder and `app.answer` of #776 (PR #777, CI queued, review pending); the issue stays ready and starts once #777 has merged. next: waiting (dependency #776)
Author
Collaborator

[loop:torbscript] wait lifted: the web builder and app.answer of #776 are on main (PR #777, c9d07e7d); the issue is ready and startable. next: waiting (ready, implement)

[loop:torbscript] wait lifted: the web builder and app.answer of #776 are on main (PR #777, c9d07e7d); the issue is ready and startable. next: waiting (ready, implement)
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261114-1734 until 2026-11-14T22:34:00Z

[loop:torbscript] claim implement by session:loop-torbscript-20261114-1734 until 2026-11-14T22:34:00Z
Author
Collaborator

[loop:torbscript] implement: opened #791 (1 commit 468d2a3e: feat(std/web): assets with fingerprinted URLs, incl. docs and skills; verified only commit lint, nothing built or run locally; unverified until CI: compile, format, tests, docs fragments). next: waiting (CI on the PR, then review)

[loop:torbscript] implement: opened https://git.torb.dev/torbscript/language/pulls/791 (1 commit 468d2a3e: feat(std/web): assets with fingerprinted URLs, incl. docs and skills; verified only commit lint, nothing built or run locally; unverified until CI: compile, format, tests, docs fragments). next: waiting (CI on the PR, then review)
Author
Collaborator

[loop:torbscript] release implement by session:loop-torbscript-20261114-1734

[loop:torbscript] release implement by session:loop-torbscript-20261114-1734
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261114-1944 until 2026-11-14T22:44:00Z

[loop:torbscript] claim implement by session:loop-torbscript-20261114-1944 until 2026-11-14T22:44:00Z
Author
Collaborator

[loop:torbscript] release implement: the worker of session:loop-torbscript-20261114-1944 ended without a result comment (no live worker, lease lapsed 2026-11-14T22:44Z). It left fix commits on #791 (3dc828cd, b01180ad, e5077ada: type check, format, std/html rel as Option, .. segment refused); CI on e5077ada is pending, review requested from argus. next: waiting (CI on PR #791, then review; a red CI starts a fix round)

[loop:torbscript] release implement: the worker of session:loop-torbscript-20261114-1944 ended without a result comment (no live worker, lease lapsed 2026-11-14T22:44Z). It left fix commits on https://git.torb.dev/torbscript/language/pulls/791 (3dc828cd, b01180ad, e5077ada: type check, format, std/html rel as Option, `..` segment refused); CI on e5077ada is pending, review requested from argus. next: waiting (CI on PR #791, then review; a red CI starts a fix round)
argus closed this issue 2026-11-15 01:36:12 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language#100
No description provided.