Skip to content

Commit

Permalink
feat(fonts): Prioritize woff2
Browse files Browse the repository at this point in the history
  • Loading branch information
jrood committed Jan 6, 2025
1 parent eacdd5c commit 9d95ebc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
17 changes: 10 additions & 7 deletions packages/gamut-styles/src/AssetProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { webFonts } from './remoteAssets/fonts';

/*
* Only preload woff2 fonts, since woff1 are only included as fallbacks.
*/
export const createFontLinks = () =>
webFonts.flatMap(({ filePath, extensions }) =>
extensions.map((ext) => (
webFonts
.filter((f) => f.extensions.includes('woff2'))
.map(({ filePath }) => (
<link
key={`${filePath}-${ext}`}
key={filePath}
rel="preload"
href={`${filePath}.${ext}`}
href={`${filePath}.woff2`}
crossOrigin="anonymous"
as="font"
type={`font/${ext}`}
type="font/woff2"
/>
))
);
));

export const AssetProvider = () => {
return <>{createFontLinks()}</>;
Expand Down
14 changes: 8 additions & 6 deletions packages/gamut-styles/src/remoteAssets/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
export const FONT_ASSET_PATH = `https://www.codecademy.com/gamut`;

// woff2 should precede woff so that browsers try woff2 first.

export const webFonts = [
{
filePath: `${FONT_ASSET_PATH}/apercu-regular-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
},
{
filePath: `${FONT_ASSET_PATH}/apercu-italic-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
style: 'italic',
},
{
filePath: `${FONT_ASSET_PATH}/apercu-bold-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
weight: 'bold',
},
{
filePath: `${FONT_ASSET_PATH}/apercu-bold-italic-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
weight: 'bold',
style: 'italic',
},
{
filePath: `${FONT_ASSET_PATH}/SuisseIntlMono-Bold-WebS`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Suisse',
weight: 'bold',
},
{
filePath: `${FONT_ASSET_PATH}/SuisseIntlMono-Regular-WebS`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Suisse',
},
];

0 comments on commit 9d95ebc

Please sign in to comment.