Skip to content

Commit bfea9f0

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

File tree

2 files changed

+34
-0
lines changed

2 files changed

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