Skip to content

Commit 9d95ebc

Browse files
committed
feat(fonts): Prioritize woff2
1 parent eacdd5c commit 9d95ebc

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

packages/gamut-styles/src/AssetProvider.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { webFonts } from './remoteAssets/fonts';
22

3+
/*
4+
* Only preload woff2 fonts, since woff1 are only included as fallbacks.
5+
*/
36
export const createFontLinks = () =>
4-
webFonts.flatMap(({ filePath, extensions }) =>
5-
extensions.map((ext) => (
7+
webFonts
8+
.filter((f) => f.extensions.includes('woff2'))
9+
.map(({ filePath }) => (
610
<link
7-
key={`${filePath}-${ext}`}
11+
key={filePath}
812
rel="preload"
9-
href={`${filePath}.${ext}`}
13+
href={`${filePath}.woff2`}
1014
crossOrigin="anonymous"
1115
as="font"
12-
type={`font/${ext}`}
16+
type="font/woff2"
1317
/>
14-
))
15-
);
18+
));
1619

1720
export const AssetProvider = () => {
1821
return <>{createFontLinks()}</>;
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
export const FONT_ASSET_PATH = `https://www.codecademy.com/gamut`;
22

3+
// woff2 should precede woff so that browsers try woff2 first.
4+
35
export const webFonts = [
46
{
57
filePath: `${FONT_ASSET_PATH}/apercu-regular-pro`,
6-
extensions: ['woff', 'woff2'],
8+
extensions: ['woff2', 'woff'],
79
name: 'Apercu',
810
},
911
{
1012
filePath: `${FONT_ASSET_PATH}/apercu-italic-pro`,
11-
extensions: ['woff', 'woff2'],
13+
extensions: ['woff2', 'woff'],
1214
name: 'Apercu',
1315
style: 'italic',
1416
},
1517
{
1618
filePath: `${FONT_ASSET_PATH}/apercu-bold-pro`,
17-
extensions: ['woff', 'woff2'],
19+
extensions: ['woff2', 'woff'],
1820
name: 'Apercu',
1921
weight: 'bold',
2022
},
2123
{
2224
filePath: `${FONT_ASSET_PATH}/apercu-bold-italic-pro`,
23-
extensions: ['woff', 'woff2'],
25+
extensions: ['woff2', 'woff'],
2426
name: 'Apercu',
2527
weight: 'bold',
2628
style: 'italic',
2729
},
2830
{
2931
filePath: `${FONT_ASSET_PATH}/SuisseIntlMono-Bold-WebS`,
30-
extensions: ['woff', 'woff2'],
32+
extensions: ['woff2', 'woff'],
3133
name: 'Suisse',
3234
weight: 'bold',
3335
},
3436
{
3537
filePath: `${FONT_ASSET_PATH}/SuisseIntlMono-Regular-WebS`,
36-
extensions: ['woff', 'woff2'],
38+
extensions: ['woff2', 'woff'],
3739
name: 'Suisse',
3840
},
3941
];

0 commit comments

Comments
 (0)