Skip to content

Commit a1d41e7

Browse files
committed
feat: add font preloading to reduce fout
1 parent 9d612f3 commit a1d41e7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<link rel="preconnect" href="https://cppalliance.org" crossorigin>
2+
<link rel="preload" href="https://cppalliance.org/fonts/NotoSansDisplay.ttf" as="font" type="font/ttf" crossorigin />
3+
<link rel="preload" href="https://cppalliance.org/fonts/NotoSansDisplay-Italic.ttf" as="font" type="font/ttf" crossorigin />
4+
<link rel="preload" href="https://cppalliance.org/fonts/NotoSansMono.ttf" as="font" type="font/ttf" crossorigin />
5+
<script>
6+
(function() {
7+
'use strict';
8+
if (!('fonts' in document)) return;
9+
10+
var fontUrls = [
11+
{ family: 'Noto Sans', url: 'https://cppalliance.org/fonts/NotoSansDisplay.ttf', style: 'normal' },
12+
{ family: 'Noto Sans', url: 'https://cppalliance.org/fonts/NotoSansDisplay-Italic.ttf', style: 'italic' },
13+
{ family: 'Noto Sans Mono', url: 'https://cppalliance.org/fonts/NotoSansMono.ttf', style: 'normal' }
14+
];
15+
16+
var fontPromises = fontUrls.map(function(fontConfig) {
17+
var fontFace = new FontFace(fontConfig.family, 'url(' + fontConfig.url + ')', {
18+
style: fontConfig.style
19+
});
20+
return fontFace.load().then(function(loadedFont) {
21+
document.fonts.add(loadedFont);
22+
return loadedFont;
23+
}).catch(function() {
24+
// Silently fail - fonts will fallback to CSS loading
25+
});
26+
});
27+
28+
Promise.all(fontPromises).catch(function() {
29+
// Silently fail - fonts will fallback to CSS loading
30+
});
31+
})();
32+
</script>

antora-ui/src/partials/head.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{> head-prelude}}
22
{{> head-title}}
33
{{> head-info}}
4+
{{> head-fonts}}
45
{{> head-styles}}
56
{{> head-scripts}}
67
{{> head-icons}}

0 commit comments

Comments
 (0)