Skip to content

Commit

Permalink
Improved font loading method for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
minimaluminium committed Jun 17, 2024
1 parent 9a2f77a commit e860b01
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 46 deletions.
2 changes: 1 addition & 1 deletion assets/built/screen.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/built/screen.css.map

Large diffs are not rendered by default.

45 changes: 1 addition & 44 deletions assets/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,50 +83,7 @@ production stylesheet in assets/built/screen.css
/* 2. Fonts
/* ---------------------------------------------------------- */

@font-face {
font-family: "Inter";
font-style: normal;
font-weight: 100 900;
font-display: swap;
src: url(../fonts/inter-roman.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
font-family: "EB Garamond";
font-style: normal;
font-weight: 400 800;
font-display: swap;
src: url(../fonts/eb-garamond-roman.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
font-family: "EB Garamond";
font-style: italic;
font-weight: 400 800;
font-display: swap;
src: url(../fonts/eb-garamond-italic.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
font-family: "JetBrains Mono";
font-style: normal;
font-weight: 100 800;
font-display: swap;
src: url(../fonts/jetbrains-mono-roman.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
font-family: "JetBrains Mono";
font-style: italic;
font-weight: 100 800;
font-display: swap;
src: url(../fonts/jetbrains-mono-italic.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Fonts are preloaded and defined in default.hbs to avoid layout shift */

/* 3. Resets
/* ---------------------------------------------------------- */
Expand Down
3 changes: 3 additions & 0 deletions default.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{{!-- Preload main styles and scripts for better performance --}}
<link rel="preload" as="style" href="{{asset "built/screen.css"}}">
<link rel="preload" as="script" href="{{asset "built/source.js"}}">

{{!-- Fonts are preloaded and defined in the default template to avoid layout shift --}}
{{> "typography/fonts"}}

{{!-- Theme assets - use the {{asset}} helper to reference styles & scripts, this will take care of caching and cache-busting automatically --}}
<link rel="stylesheet" type="text/css" href="{{asset "built/screen.css"}}">
Expand Down
15 changes: 15 additions & 0 deletions partials/typography/fonts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{!-- Sans-serif font is always loaded, because it's the default font for some part of the theme regardless of the settings --}}
{{> "fonts/sans"}}

{{#match @custom.title_font "Modern sans-serif"}}
{{#match @custom.body_font "Elegant serif"}}
{{> "fonts/serif"}}
{{/match}}
{{else match @custom.title_font "Elegant serif"}}
{{> "fonts/serif"}}
{{else}}
{{> "fonts/mono"}}
{{#match @custom.body_font "Elegant serif"}}
{{> "fonts/serif"}}
{{/match}}
{{/match}}
21 changes: 21 additions & 0 deletions partials/typography/mono.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<link rel="preload" as="font" type="font/woff2" href="{{asset "fonts/jetbrains-mono-roman.woff2"}}" crossorigin="anonymous">
<link rel="preload" as="font" type="font/woff2" href="{{asset "fonts/jetbrains-mono-italic.woff2"}}" crossorigin="anonymous">
<style>
@font-face {
font-family: "JetBrains Mono";
font-style: normal;
font-weight: 100 800;
font-display: optional;
src: url({{asset "fonts/jetbrains-mono-roman.woff2"}}) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: "JetBrains Mono";
font-style: italic;
font-weight: 100 800;
font-display: optional;
src: url({{asset "fonts/jetbrains-mono-italic.woff2"}}) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
</style>
11 changes: 11 additions & 0 deletions partials/typography/sans.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<link rel="preload" as="font" type="font/woff2" href="{{asset "fonts/inter-roman.woff2"}}" crossorigin="anonymous">
<style>
@font-face {
font-family: "Inter";
font-style: normal;
font-weight: 100 900;
font-display: optional;
src: url({{asset "fonts/inter-roman.woff2"}}) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
</style>
21 changes: 21 additions & 0 deletions partials/typography/serif.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<link rel="preload" as="font" type="font/woff2" href="{{asset "fonts/eb-garamond-roman.woff2"}}" crossorigin="anonymous">
<link rel="preload" as="font" type="font/woff2" href="{{asset "fonts/eb-garamond-italic.woff2"}}" crossorigin="anonymous">
<style>
@font-face {
font-family: "EB Garamond";
font-style: normal;
font-weight: 400 800;
font-display: optional;
src: url({{asset "fonts/eb-garamond-roman.woff2"}}) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: "EB Garamond";
font-style: italic;
font-weight: 400 800;
font-display: optional;
src: url({{asset "fonts/eb-garamond-italic.woff2"}}) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
</style>

0 comments on commit e860b01

Please sign in to comment.