Skip to content

build: reduce bundle size with CSS compaction and two Terser passes - #484

Merged
chhoumann merged 4 commits into
masterfrom
build/size-levers
Oct 15, 2026
Merged

chhoumann merged 4 commits into
masterfrom
build/size-levers

Conversation

@chhoumann

@chhoumann chhoumann commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reduce the production bundle by 328 gzip bytes (measured against master bdf3b82 by the independent verifier V-484) with a second Terser compression pass and conservative CSS formatting compaction. Headroom becomes 638 gzip bytes and 7,632 raw bytes. Both budgets remain unchanged.

Build (against master bdf3b82, V-484) Raw bytes Gzip level 9 bytes Gzip saving
Master baseline 323,584 102,690 0
Terser passes 2 alone 323,074 102,434 256
CSS compaction alone 322,878 102,609 81
Combined 322,368 102,362 328

The author's original measurement against master eafb24b was -347 (passes 2: -264, CSS: -79); V-484 reproduced it exactly. The smaller saving on current master comes from the code #479 and #482 added (compressor context and longer scoped class ids), not from a change in the levers.

Each option was built five times with identical bytes. Savings are small because Svelte already removes most CSS formatting and gzip compresses repeated formatting well. A second Terser pass removes code exposed by the first pass. Later passes produce worse gzip results. Combined gzip savings are not additive.

The CSS helper preserves selectors, values, custom-property spacing, and inline comments. Production getter reads, ES2020, the no-tagged-template rule, and the hash algorithm remain intact. Short hashes were rejected because they weaken collision resistance. Full-strength compact encodings increased gzip size. No source or dependency files change.

The evidence archive contains the complete per-lever table, rejected experiments, rerunnable measurement scripts, raw logs, mutation results, and screenshots.

Measurements, verification logs, and pixel evidence

Verification

All commands ran with Node 22.23.2 through fnm exec --using 22.

  • npm run lint, npm run format:check, npm run typecheck, and npm run build passed.
  • npm run test passed, 124 files and 2,613 tests. Both Svelte checks found zero warnings or errors.
  • npm run test:tooling passed, 4 files and 30 tests.
  • npm run docs:build passed, 18 pages and 112 legacy fragments.
  • npm run size passed at 320,419 raw bytes and 101,490 gzip bytes.
  • npm run test:e2e passed on a fresh vault in Obsidian 1.14.4 on Linux, 28 files and 207 tests. A full 1.13.7 run passed 198 tests before the final test-only master merge. All 39 tests in its five changed E2E files then passed on 1.13.7 against the identical bundle. No unexpected renderer errors occurred, and cleanup confirmed no remaining instance processes.
  • Pixel checks covered all 24 verify states at 320, 820, and 390 pixels in both themes. All 142 cases have an exact master/candidate match. The initial pass had 94 changed pixels across three phone screens. Unchanged-build controls resolved each difference without masks or tolerance. The originals and control comparisons are retained, and all 24 contact sheets were inspected.

Five plausible wrong changes each failed a test before restoration:

Mutant Failing test
Disconnect the CSS preprocessor buildOptions.test.ts
Strip custom-property spacing compactCss.test.ts
Delete spaces around calc subtraction compactCss.test.ts
Clear comments between selector and brace compactCss.test.ts
Set pure_getters: true buildOptions.test.ts, getter read count becomes zero

Independent reviews completed with Claude Fable 5.1 and GPT-6 Astra. The production-build test now sets and asserts production mode after Astra caught Vitest's default test environment. A fresh review accepted the fix, and Claude Opus 5.5 verified the artifact, size, syntax floor, and focused tooling tests.

Release impact

None. No settings, storage, API, URI, or migration changes. No user-documentation changes are needed.

Note

Reduce bundle size with CSS compaction and two Terser passes

Adds compactCss in compact-css.ts, a PostCSS-based serializer that removes formatting-only whitespace while preserving comments, quoted values, and custom-property spacing.

  • In vite.config.ts, the Svelte style preprocessor applies compactCss after comment stripping in production mode only; development builds are unchanged.
  • Terser compression now runs with two passes, keeping the existing pure-getter and mangling settings.
  • Adds unit tests in compactCss.test.ts and a production build integration test in buildOptions.test.ts that runs the built output in a VM.
  • Risk: production CSS output changes shape; check the compactCss token-preservation cases in compactCss.test.ts if styles regress.

Macroscope summarized 466c1c7.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Deploying podnotes with  Cloudflare Pages  Cloudflare Pages

Latest commit: 466c1c7
Status: ✅  Deploy successful!
Preview URL: https://25827fdb.podnotes.pages.dev
Branch Preview URL: https://build-size-levers.podnotes.pages.dev

View logs

@chhoumann
chhoumann merged commit 44856a9 into master Oct 15, 2026
17 checks passed
@chhoumann
chhoumann deleted the build/size-levers branch October 15, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant