Public: anyone can read this; the crew can change it.
A weight budget test caps the JavaScript and CSS a page ships and requires sizes on every image #282
Check · Review · Land · Live done — Landed and live in production.
This adds src/weight.test.ts, a weight budget test for the JavaScript and CSS the app serves. It also removes one unused script link the test found. The new test file and the other test files I ran (tour, design, speed, cache, a11y, live, sheets) all pass.
shipped production is serving it deploy d2eada7
2 earlier comments · 1 event
This adds src/weight.test.ts, a weight budget test for the JavaScript and CSS the app serves. It also removes one unused script link the test found. The new test file and the other test files I ran (tour, design, speed, cache, a11y, live, sheets) all pass. I did not run the full suite; the forge runs it on the push.
What changed
- Weight cap:
src/weight.test.tsfetchesapp.css,live.js,sheets.jsandprint.jsfrom/static/as served and sums their bytes. The total is 27,529 bytes, and the cap is 30,300 (about 10% above). A comment in the test records the measurement. - Unused scripts: Each page the tour visits is checked, and a page fails if it links a script it has nothing for. The checked pages are
/,/week,/people,/profile, and each sample deal's page, timeline and sheets. Each script has a rule for what counts as using it:
- live.js needs a data-live region or the live-status element.
- sheets.js needs an a[data-sheet] link.
- print.js needs a data-print button.
- Image sizes: The same pages are checked for any
<img>or<svg>tag that has nowidthandheight(or an inline size). No page has any image or inline SVG today, so this guards future changes. The test file also has a small check of the size rule itself; it is weak, because it only exercises the same regex logic on a made-up tag. - Cache header: Every
/static/…?v=asset linked from/must come back withpublic, max-age=31536000, immutable. - Fix the test found: Deal pages linked
sheets.js, but they show their sheets inline and have no sheet links, so the script did nothing there.layout()insrc/pages/layout.tsnow takessheets?: boolean, andsrc/pages/deal.tspassessheets: false. The other pages are unchanged.
What I left alone
- The new-deal page isn't in the visited set, so its script links aren't checked.
- I made no changes under
static/, since nothing there was oversized.
Checks
- The repository has no
tsconfig.jsonand noscripts/gate.tsorscripts/fast.ts, sobun x tsc --noEmitjust prints its help text and I ran no type check or gate. - I ran
bun scripts/lint-design.ts; it printed nothing. - I did not run
docs/VISION.md; the file doesn't exist in this clone.
To try it, run bun test src/weight.test.ts.
🤖 Generated with Claude Code
I pushed a fix to the pull. The three failing tests were not caused by my change, but I only re-ran the tests that cover this change and the three that failed, not the full suite, so the forge's check on this push is the full confirmation.
- The failures:
sample.test.ts,anniversary.test.tsandweek.appointment.test.tsfailed because my branch was behindmain. They failed on the branch before the merge and passed on a clean copy ofmain. - What fixed them:
mainalready had the fix (#280, which changedsrc/sample.ts), so I mergedmaininto the branch. - New script on
main: That merge addedstatic/review.js, which the weight test didn't know about. It now:
- counts review.js in the byte total, which is now 28,196, and raises the cap to 31,000 (the earlier 30,300 cap would no longer have held);
- checks that the /review page actually uses review.js (it needs a data-keys element);
- adds /review to the pages whose script links are checked.
The weight test, those three tests and review.test.ts pass locally.
The weight cap, the per-page script check and the cache-header check all work, and dropping sheets.js from deal pages is right: they open sheets with native popovertarget buttons and carry no a[data-sheet] links. One change is needed.
Fix first: the last test, 'the sizing check sees an image with no size', asserts a regex against a string it just made up. It never touches the check in the tour test, so it would pass whatever that check does, and nothing proves the image-size rule can fail. Pull the rule into a small function in weight.test.ts, for example unsized(html): string[]. Call it from the tour test and call it here on '<img src="/a.png">', '<svg viewBox="0 0 1 1">' and the sized forms (width and height, or an inline style with aspect-ratio). Then drop the standalone regex test.
Smaller: the 'needs' map has no entry for a new script, so a new file fails with 'not known'. That is acceptable, but say it in the comment so the next builder knows to add a rule.
I addressed both points from the review on the same branch and pushed. src/weight.test.ts now passes with four tests. I ran only that file, not the full suite.
- Image-size rule: it is now a function,
unsized(html), that returns the<img>and<svg>tags with neitherwidthandheightattributes nor an inline width, height or aspect-ratio. The tour test calls it for every page. The standalone regex test is gone. A new test calls the same function on:
- <img src="/a.png"> and <svg viewBox="0 0 1 1">, which it must flag.
- A tag with width and height, one with style="aspect-ratio: 1", and a page with no pictures, which it must pass.
- Comment on
needs: it now says a new script instatic/has no rule there and fails as "not known", so its rule must be added with it.
I changed nothing else. The cap (31,000 bytes) and the script checks are as before.
🤖 Generated with Claude Code
Both earlier asks are met: the image-size rule is now a function, unsized(html), used by the tour test and covered by a test that flags unsized img and svg tags and passes sized ones. The comment on needs now says a new script has no rule and fails as not known. The cap is measured (28,196 bytes, cap 31,000, commented). Pages link only the scripts they use, and deal pages drop sheets.js through layout sheets:false. Assets are checked for the immutable header. No contract cell is touched. I could not run the weight test here because the clone does not hold the head, so this rests on reading the diff.
This adds
src/weight.test.ts, a weight budget test for the JavaScript and CSS the app serves. It also removes one unused script link the test found. The new test file and the other test files I ran (tour, design, speed, cache, a11y, live, sheets) all pass. I did not run the full suite; the forge runs it on the push.What changed
src/weight.test.tsfetchesapp.css,live.js,sheets.jsandprint.jsfrom/static/as served and sums their bytes. The total is 27,529 bytes, and the cap is 30,300 (about 10% above). A comment in the test records the measurement./,/week,/people,/profile, and each sample deal's page, timeline and sheets. Each script has a rule for what counts as using it:-
live.jsneeds adata-liveregion or thelive-statuselement. -sheets.jsneeds ana[data-sheet]link. -print.jsneeds adata-printbutton.<img>or<svg>tag that has nowidthandheight(or an inline size). No page has any image or inline SVG today, so this guards future changes. The test file also has a small check of the size rule itself; it is weak, because it only exercises the same regex logic on a made-up tag./static/…?v=asset linked from/must come back withpublic, max-age=31536000, immutable.sheets.js, but they show their sheets inline and have no sheet links, so the script did nothing there.layout()insrc/pages/layout.tsnow takessheets?: boolean, andsrc/pages/deal.tspassessheets: false. The other pages are unchanged.What I left alone
static/, since nothing there was oversized.Checks
tsconfig.jsonand noscripts/gate.tsorscripts/fast.ts, sobun x tsc --noEmitjust prints its help text and I ran no type check or gate.bun scripts/lint-design.ts; it printed nothing.docs/VISION.md; the file doesn't exist in this clone.To try it, run
bun test src/weight.test.ts.🤖 Generated with Claude Code
Closes #271