minify

command
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Command minify builds the files the library serves, and measures them.

It does two jobs that belong together because the second is only meaningful against the artifact the first produced:

  1. Bundle client/runtime.js and its generated codec into one self-contained IIFE, minified, and write it to live/clientjs/gotth-live.min.js — the directory the public package embeds it from by exact filename. That file is committed. A clean clone therefore needs no minifier, no node and no network to serve the runtime (PRD FR-7, G11, NFR-5).

    The dev inspector (client/inspector.js) is bundled the same way to live/clientjs/gotth-live-inspector.min.js, and held to its own ceiling of 40,960 bytes gzipped. It is a SECOND artifact rather than a region of the first because NFR-8 requires it to be a separate opt-in file that does not count against NFR-2 — so the two ceilings here are two requirements, and neither number may be spent on the other's code.

    Dev reload (client/dev-reload.js) is a THIRD artifact on the same terms, to live/clientjs/gotth-live-dev-reload.min.js, with a ceiling of 8,192 bytes gzipped. FR-57 has no byte budget of its own in the PRD; the ceiling exists anyway, because the reason the inspector got one applies here unchanged — a dev-only file with no gate is a file that grows until somebody measures it, and the number that must not move is NFR-2's.

    It is emitted THERE and nowhere else. Keeping a second copy beside the sources would create a two-copy equality invariant, and an invariant you do not create is better than one somebody has to check (L9-1 addendum to docs/reviews/module-init.md, 2026-08-04). client/ stays the source of truth for the runtime source, the generated codec and the node tests, and stays a directory with no Go file in it.

  2. Measure it: gzip -9 over the minified bundle is the PRD NFR-2 gate at 12,288 bytes, and each //#region in the source gets a measured marginal cost so NFR-3's per-subsystem ledger is a measurement rather than an estimate.

How a subsystem is measured, and what the numbers do not mean

Two columns, because neither alone is honest.

MINIFIED B is the region minified on its own. It is exact, it is additive, and it says where the source actually went. It slightly over-counts against the bundle, because bundling renames identifiers across the whole file.

MARGINAL GZIP B is gzip(baseline) - gzip(baseline with that region deleted): the compressed bytes the file would lose if the subsystem were not there. That is the number that answers "what is this costing me".

The baseline for the marginals is built with tree shaking DISABLED, and the shipped artifact is built with it enabled. Both numbers are reported. The reason is that deleting a region also deletes the last use of things it referenced, so a tree-shaken variant measures the dead-code cascade rather than the region — the first draft of this tool reported a subsystem as costing more than the whole file, which is how the problem announced itself.

Marginals do not sum to the total, and no arithmetic here pretends they do. DEFLATE shares matches between regions — a string literal in the transport region compresses better because the event region already used it — so the shared saving belongs to no single subsystem. The residual is reported as its own line rather than distributed, because distributing it would be an invention.

Why esbuild, and why in its own module

The minifier is a contributor tool. It lives in candace/pkg/gotth/tools/ with its own go.mod so esbuild can never reach a consumer's build graph, which is the arrangement docs/dependencies.md §3 already settled. Node is not used and is not available: .dis/Dockerfile deliberately has no node, and this runs there.

Usage:

go run ./minify            # build and measure both artifacts
go run ./minify -check     # fail if either committed artifact is stale

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL