Skip to content

Add publicly accessibly font file for easy import into projects #1

@noClaps

Description

@noClaps

Inter uses a font file at https://rsms.me/inter/inter.css to host the Inter font files for everyone using the project. This makes it really easy to use it, since it's a simple @import into your CSS file to use. I'd like if this could also be done for Server Mono.

The code in globals.scss:

@font-face {
font-family: 'Mono';
src: url('https://intdev-global.s3.us-west-2.amazonaws.com/public/internet-dev/0a26b101-f97b-41c3-a0cd-205358c7b3f7.woff') format('woff');
}
@font-face {
font-family: 'MonoSlanted';
src: url('https://intdev-global.s3.us-west-2.amazonaws.com/public/internet-dev/3bb6457d-ca97-4038-87e4-f1333e0656e9.woff') format('woff');
}

should be copied/separated into a separate CSS file that will not be bundled into the static output. I'm not familiar with Next.js but I imagine this would be in the public/ directory.

The code should be:

@font-face {
    font-family: 'Mono';
    font-style: normal;
    font-display: swap;
    src: url('https://intdev-global.s3.us-west-2.amazonaws.com/public/internet-dev/0a26b101-f97b-41c3-a0cd-205358c7b3f7.woff') format('woff');
}

@font-face {
    font-family: 'MonoSlanted';
    font-style: italic;
    font-display: swap;
    src: url('https://intdev-global.s3.us-west-2.amazonaws.com/public/internet-dev/3bb6457d-ca97-4038-87e4-f1333e0656e9.woff') format('woff');
}

Also, since the woff2 files are available, and it's only IE that doesn't support it, you can change the font file and format to woff2. You can also list multiple url and format values inside src if you'd like to have both or multiple formats. The user's browser will pick the best supported format automatically.

@font-face {
    /* ... */
    src: url("[WOFF2 file url].woff2") format("woff2"), url("[WOFF file url].woff") format("woff")
}

These can also be pointed to the locally built files rather than to AWS, but that's up to you. Simply adding the font files to the public/ directory, or whatever copies the files directly to the output, should work. The benefit for users is that it's one less request they have to make to load the font, since with the current setup it would first make a request to https://servermono.com to fetch the CSS, and then make a request to amazonaws.com to fetch the font files.

You can see Inter's CSS file linked above for reference on how this can be set up.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions