Skip to content

Commit d37b7e6

Browse files
committed
Prevent font loading layout shifts
1 parent 60f3520 commit d37b7e6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎src/layouts/BaseLayout.astro‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Sidebar from "../components/Sidebar.astro";
33
import MobileNavigation from "../components/MobileNavigation.astro";
44
import { canonicalSitePath, site } from "../data/site";
55
import type { NewsItem } from "../lib/legacy-content";
6+
import openSansRegularUrl from "../../fonts/Open_Sans/OpenSans-Regular.woff2?url";
7+
import ralewayMediumUrl from "../../fonts/Raleway/Raleway-Medium.woff2?url";
68
import "../styles/global.css";
79
810
interface Props {
@@ -57,6 +59,8 @@ const structuredData = article
5759
<meta name="description" content={description} />
5860
<meta name="keywords" content="gecode, constraint programming, constraint solver, constraint toolkit" />
5961
<meta name="generator" content={Astro.generator} />
62+
<link rel="preload" href={openSansRegularUrl} as="font" type="font/woff2" crossorigin />
63+
<link rel="preload" href={ralewayMediumUrl} as="font" type="font/woff2" crossorigin />
6064
{errorPage && <meta name="robots" content="noindex" />}
6165
{!errorPage && <link rel="canonical" href={canonical} />}
6266
<link rel="icon" href="/images/gecode-logo.ico" sizes="any" />

‎src/styles/global.css‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
url("../../fonts/Open_Sans/OpenSans-Regular.ttf") format("truetype");
99
font-style: normal;
1010
font-weight: 400;
11-
font-display: swap;
11+
font-display: optional;
1212
}
1313

1414
@font-face {
@@ -17,7 +17,7 @@
1717
url("../../fonts/Open_Sans/OpenSans-RegularItalic.ttf") format("truetype");
1818
font-style: italic;
1919
font-weight: 400;
20-
font-display: swap;
20+
font-display: optional;
2121
}
2222

2323
@font-face {
@@ -26,7 +26,7 @@
2626
url("../../fonts/Raleway/Raleway-Medium.ttf") format("truetype");
2727
font-style: normal;
2828
font-weight: 500;
29-
font-display: swap;
29+
font-display: optional;
3030
}
3131

3232
@font-face {
@@ -35,7 +35,7 @@
3535
url("../../fonts/Raleway/Raleway-MediumItalic.ttf") format("truetype");
3636
font-style: italic;
3737
font-weight: 500;
38-
font-display: swap;
38+
font-display: optional;
3939
}
4040

4141
@font-face {
@@ -44,7 +44,7 @@
4444
url("../../fonts/Roboto_Mono/RobotoMono-Regular.ttf") format("truetype");
4545
font-style: normal;
4646
font-weight: 400;
47-
font-display: swap;
47+
font-display: optional;
4848
}
4949

5050
@font-face {
@@ -53,7 +53,7 @@
5353
url("../../fonts/Roboto_Mono/RobotoMono-RegularItalic.ttf") format("truetype");
5454
font-style: italic;
5555
font-weight: 400;
56-
font-display: swap;
56+
font-display: optional;
5757
}
5858

5959
@theme {

0 commit comments

Comments
 (0)