feat(portal): preload site fonts from sd _hashes#73
Open
BatLeDev wants to merge 1 commit into
Open
Conversation
60a156d to
396c656
Compare
396c656 to
7ef1a21
Compare
7ef1a21 to
195cab0
Compare
195cab0 to
f7b5f91
Compare
f7b5f91 to
9925221
Compare
9925221 to
0fef125
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preload a portal's custom body/heading fonts so the browser fetches them earlier, shortening the serial HTML→
_theme.css→woff2 chain.Why: custom site fonts were only discovered after
_theme.cssloaded, delaying first paint with the correct typeface.What changed:
fonts/service.ts: extract a sharedgetFonthelper; addgetFontFamilyAssets(returns the@font-faceCSS + a preload URL from a single DB/file read) andpickPreloadUrl(normal-style, latin-subset regular/variable face).getFontFamilyCssunchanged in behavior.portals/service.ts:getThemeFontFieldsresolves body/heading font CSS plus a singlepreloadLinkslist. Each font link is built withas: 'font',crossorigin: trueand the MIMEtypederived from the URL — the{ href, as, type, crossorigin }objects carry everything the consumer needs.api/src/app.ts+ui/index.html: the portals-manager UI (a Vue SPA served by lib'sserve-spa) opts into preloads via a{PRELOAD_LINKS}placeholder and letsserve-spafetch_hashesitself (privateDirectoryUrloption) — removing the duplicatedgetSiteHashes(utils/site.ts, which also hadTHEME_CSS_HASH/PUBLIC_SITE_INFO_HASHswapped).portal/server/plugins/sd-resources.ts: read the optionalpreloadLinksfield from_hashesand emit one HTML-escaped<link rel="preload">per entry (driven byas/type/crossorigin) before the theme stylesheet.Regression risks:
_hashesemitpreloadLinks). Backward-compatible in isolation:hashes.preloadLinks ?? []→ no preloads, nothing breaks — mind the deploy ordering.preloadLinkskey sent to SD, which relays it as-is.getFontFamilyCssnow delegates to the newgetFonthelper; behavior unchanged but the font router shares this path.hrefmust round-trip through_hashesbyte-identical to thesrc: url(...)in the generated@font-facefor the browser to dedupe.