feat(ui): preload the Inter font when a CodeFloe theme is active #215
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!215
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/preload-inter-font"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #195.
Motivation
The CodeFloe themes render with self-hosted Inter, but the browser only discovers
inter-latin.*.woff2after it has downloaded and parsedindex.css.On a cold load text first paints in the fallback font and then swaps, a visible layout shift on every first visit.
Changes
templates/base/head.tmpl: add a single{{template "base/codefloe_head" .}}hook before the stylesheets.templates/base/codefloe_head.tmpl: whenThemeNamestarts withcodefloe-, emit<link rel="preload" as="font" type="font/woff2" crossorigin>for the Latin Inter file.modules/templates/codefloe_fonts.go:CodefloeFontPreloadfinds the content-hashedinter-latin.<hash>.woff2inassets/fontsof the public asset FS, once per process. No webpack manifest is needed. If the file is missing, or a stale build left several, it returns nothing and no preload is emitted.modules/templates/helper.go: registerCodefloeFontPreload.README.md: add aFont preloadrow.Only the Latin subset is preloaded; the other subsets keep loading on demand by
unicode-range.Verification
codefloe-autothe head contains<link rel="preload" href="/assets/fonts/inter-latin.4f2981d8.woff2" ...>, matching the URLindex.cssreferences; withforgejo-autono preload is emitted.@font-face) and there is no "preloaded but not used" console warning.make lint-go(pinned toolchain) andprekpass.6f4071a00ed2ff5a503cd2ff5a503c046e02ee71