Skip to content

feat: expose font preloads in /sites/_hashes#128

Draft
BatLeDev wants to merge 1 commit into
masterfrom
font-preloads-via-hashes
Draft

feat: expose font preloads in /sites/_hashes#128
BatLeDev wants to merge 1 commit into
masterfrom
font-preloads-via-hashes

Conversation

@BatLeDev

@BatLeDev BatLeDev commented Jun 11, 2026

Copy link
Copy Markdown
Member

Expose a fonts list in GET /sites/_hashes so SPA consumers (@data-fair/lib serve-spa, the Nuxt portal) can emit <link rel="preload" as="font"> and fetch site fonts in parallel with the theme stylesheet.

What changed:

  • The files to preload come from the theme's bodyFontPreloadUrls / headingFontPreloadUrls arrays (new theme-schema fields, populated by the portals manager for custom fonts). getThemeFontPreloads resolves {SITE_PATH}, dedupes, and derives the MIME type from the extension (omitted when unknown).
  • Per-slot fallback mirroring getThemeCss: a slot uses the site's preload when it sets that font's CSS, otherwise the default theme's self-hosted Nunito preload — so a font is never preloaded unless it is actually rendered.
  • GET /sites/_hashes now also returns fonts: [{ href, type? }] (site and default branches).
  • config.ts drops the Nunito preload defaults when the operator configures a custom font via THEME_*, so they can't shadow it.

Why: load fonts in parallel with the theme instead of waiting for _theme.css to fetch+parse, breaking the serial HTML → _theme.css → woff2 chain.

Regression risks:

  • _hashes gains an additive fonts field; consumers tolerate its absence (?? []). No existing export signatures changed.
  • Reads the new theme fields bodyFontPreloadUrls / headingFontPreloadUrls, defined in @data-fair/lib (feat: site font preloads (theme schema + SPA injection) lib#40). A site without them (or without a custom font) falls back to the default Nunito preload; nothing breaks if they're absent.

The sites _hashes payload exposes a `fonts` list so portals and lib-served
SPAs can emit `<link rel="preload">` for the site fonts before the theme
stylesheet.

- the preload URLs live in the theme (`bodyFontPreloadUrls` /
  `headingFontPreloadUrls`), populated by the portals manager for custom fonts.
- each slot falls back to the configured default theme (Nunito) preload,
  mirroring getThemeCss, so a font is never preloaded unless it is used.
- the mime type is derived from the URL extension and omitted when unknown.
@BatLeDev BatLeDev force-pushed the font-preloads-via-hashes branch from 53ae2ba to 4f84b96 Compare June 12, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant