|
| 1 | +# Ship common font faces inline and the rest as assets |
| 2 | + |
| 3 | +### Title: Ship common font faces inline and the rest as assets |
| 4 | + |
| 5 | +### Proposed by: Jan Librowski |
| 6 | + |
| 7 | +### Date: 31.08.2026 |
| 8 | + |
| 9 | +## Context |
| 10 | + |
| 11 | +Vite library mode inlined all twelve Poppins and Inter font faces as base64. |
| 12 | +The built stylesheet consequently carried approximately 382 KB of fonts: |
| 13 | +`index.css` was 509 KB, and the SDK stylesheet that bundles it was 591 KB. |
| 14 | +Most consumers need only the Poppins 400 and 600 latin faces declared by the |
| 15 | +typography classes, while the other weights, Inter, and extended latin subsets |
| 16 | +can load on demand. |
| 17 | + |
| 18 | +## Decision |
| 19 | + |
| 20 | +Generate the twelve `@font-face` rules after Vite finishes. Keep Poppins 400 |
| 21 | +and 600 latin inline, and copy the other ten `.woff2` files into `dist/assets`. |
| 22 | +Apply fontsource's subset-specific unicode ranges and `font-display: swap` so a |
| 23 | +browser requests only the faces needed by the document. Ship the Poppins and |
| 24 | +Inter SIL Open Font License 1.1 texts beside the font assets. |
| 25 | + |
| 26 | +This reduces `index.css` from 509 KB to 150 KB and the SDK stylesheet from 591 |
| 27 | +KB to 230 KB while preserving existing imports and immediate rendering for the |
| 28 | +two common faces. |
| 29 | + |
| 30 | +## Alternative Options Considered |
| 31 | + |
| 32 | +- **Keep everything inline.** Rejected because every consumer would continue |
| 33 | + downloading approximately 382 KB of font data before using any face. |
| 34 | +- **Ship everything as assets.** Rejected because even the common Poppins 400 |
| 35 | + and 600 latin faces would require additional requests before normal UI text |
| 36 | + renders. |
| 37 | +- **Patch the Vite configuration.** Rejected because Vite library mode ignores |
| 38 | + the normal asset inline limit, so configuration alone cannot produce the |
| 39 | + required mix of inline and emitted faces. |
| 40 | +- **Use a CDN.** Rejected because it adds an external runtime dependency, |
| 41 | + changes Content Security Policy requirements, and prevents the package from |
| 42 | + remaining self-contained. |
| 43 | + |
| 44 | +## Consequences |
| 45 | + |
| 46 | +- Consumers that define `font-src` in Content Security Policy must allow |
| 47 | + `'self'` or the package-serving origin instead of relying only on `data:`. |
| 48 | +- Consumers that copy stylesheets must preserve the relative `dist/assets` |
| 49 | + layout. |
| 50 | +- A future refactor that simplifies the pipeline back to fontsource CSS imports |
| 51 | + can silently reintroduce approximately 382 KB of inline font data. |
| 52 | +- The build must keep the font asset references and shipped license files in |
| 53 | + sync with `FONT_FACES`. |
| 54 | + |
| 55 | +## Status |
| 56 | + |
| 57 | +accepted |
0 commit comments