Skip to content

Commit 2cbe6e6

Browse files
committed
feat(fonts): optimize font loading
Optimize font loading to reduce first contentful paint and the last contentful paint lighthouse metrics.
1 parent 135ea46 commit 2cbe6e6

3 files changed

Lines changed: 32 additions & 15 deletions

File tree

src/app/layout.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Metadata } from 'next';
22
import type { FC, ReactNode } from 'react';
33

4+
import { Raleway, Source_Sans_3 } from 'next/font/google';
5+
import localFont from 'next/font/local';
46
import {
57
LastUpdated,
68
Layout,
@@ -11,6 +13,32 @@ import { getPageMap } from 'nextra/page-map';
1113
import themeConfig from '@/theme.config';
1214
import './styles.css';
1315

16+
const raleway = Raleway({
17+
weight: ['300', '400', '700'],
18+
subsets: ['latin'],
19+
display: 'swap',
20+
variable: '--font-raleway',
21+
});
22+
23+
const sourceSans = Source_Sans_3({
24+
weight: ['300', '400', '700'],
25+
subsets: ['latin'],
26+
display: 'swap',
27+
variable: '--font-source-sans',
28+
});
29+
30+
const pragmataPro = localFont({
31+
src: [
32+
{
33+
path: '../../public/fonts/logo-font.woff2',
34+
weight: 'normal',
35+
style: 'normal',
36+
},
37+
],
38+
display: 'swap',
39+
variable: '--font-pragmata-pro',
40+
});
41+
1442
export const metadata: Metadata = {
1543
description:
1644
'ConnectBot is a secure shell client for the Android platform.',
@@ -45,7 +73,7 @@ const RootLayout: FC<LayoutProps> = async ({ children }) => {
4573
);
4674

4775
return (
48-
<html lang="en" suppressHydrationWarning>
76+
<html lang="en" suppressHydrationWarning className={`${raleway.variable} ${sourceSans.variable} ${pragmataPro.variable}`}>
4977
<Head
5078
backgroundColor={{
5179
dark: 'rgb(15,23,42)',

src/app/styles.css

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
@import 'nextra-theme-docs/style.css';
2-
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700');
3-
@import url('https://fonts.googleapis.com/css?family=Raleway:300,400,700');
4-
5-
@font-face {
6-
font-family: 'Essential PragmataPro';
7-
font-style: normal;
8-
font-weight: normal;
9-
src:
10-
url('/fonts/logo-font.woff2') format('woff2'),
11-
url('/fonts/logo-font.woff') format('woff');
12-
}
132

143
body {
15-
font-family: 'Raleway', Arial, sans-serif;
4+
font-family: var(--font-raleway), Arial, sans-serif;
165
font-size: 0.85em;
176
}
187

198
article p {
20-
font-family: 'Source Sans Pro', Arial, sans-serif;
9+
font-family: var(--font-source-sans), Arial, sans-serif;
2110
margin: 0.75rem 0;
2211
}
2312

src/content/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ searchable: false
55

66
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', margin: '2rem 0', gap: '0.5rem' }}>
77
<img src="/logo.png" alt="ConnectBot logo" width={128} height={128} />
8-
<h1 style={{ fontFamily: 'Essential PragmataPro', fontSize: '2.5rem', margin: 0, lineHeight: 1 }}>ConnectBot</h1>
8+
<h1 style={{ fontFamily: 'var(--font-pragmata-pro)', fontSize: '2.5rem', margin: 0, lineHeight: 1 }}>ConnectBot</h1>
99
<p className="tagline" style={{ fontSize: '1.2rem', color: '#666', margin: 0 }}>The first SSH client for Android.</p>
1010
</div>
1111

0 commit comments

Comments
 (0)