Partitioning a CSS monolith without breaking the budget
How S3 killed style.css, moved to design tokens, and kept first-paint CSS under 12 KiB gzip.
The old style.css was a single file mixing tokens, layout, features and one-off hacks. Every route paid for every pixel.
The plan
- Extract tokens into
tokens.css(the only place hex lives). - Ship feature CSS with the feature (
mirror.css,lab.css,diorama.css). - Ban hex literals outside tokens with ESLint + a
check-hexscript inlint.
What broke
Tailwind was still in the lockfile after removal from config. npm install regenerated a clean lock with zero Tailwind packages. Orphan selectors were caught by a new gate before they shipped.
Result
First-paint CSS: 9.95 KiB gzip / 12 KiB budget. No monolith, no silent color drift.