-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce FOUT #21427
Comments
Some relevant links explaining why self-hosting (and preloading, sub-setting binaries, and using variable fonts wherever possible + a bunch other tricks) is preferable to using Google Fonts: |
Nice CLI tool for sub-setting binaries: https://github.com/zachleat/glyphhanger |
Sample code for self-hosting: /* Variable fonts */
/* English */
@font-face {
font-family: 'FooV';
font-weight: 400 700; /* Whatever's actually in the font file, same for font-style */
font-display: swap; /* https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display#values */
font-style: oblique 0deg 10deg;
src: url('https://foo.bar/fonts/en.var.woff2') format('woff2');
unicode-range: U+0020-007F, U+AB, U+BB;
}
/* Cyrillic */
@font-face {
font-family: 'FooV';
font-weight: 400 700;
font-display: swap;
font-style: oblique 0deg 10deg;
src: url('https://foo.bar/fonts/cyr.var.woff2') format('woff2');
unicode-range: U+401, U+404, U+406, U+407, U+410-44F, U+451, U+454, U+456, U+457, U+490, U+491;
}
...
/* Duplicating this all for all needed Unicode ranges */
/* Non-variable fonts */
/* English */
@font-face {
font-family: 'Foo';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url('https://foo.bar/fonts/en.regular.woff2') format('woff2');
unicode-range: U+0020-007F, U+AB, U+BB;
}
@font-face {
font-family: 'Foo';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url('https://foo.bar/fonts/cyr.regular.woff2') format('woff2');
unicode-range: U+0020-007F, U+AB, U+BB;
}
...
/* Duplicating for all necessary weights and styles and Unicode ranges*/
/* Declaring a fallback */
@font-face {
font-family: 'Foo-Fallback';
size-adjust: 109.71%;
src: local('Arial'); /* Arial is the most available fallback for sans-serifs. ref: http://fontfamily.io */
}
/* Applying variable when supported */
* {
font-family: 'Foo', 'Foo-Fallback', sans-serif;
}
@supports (font-variation-settings: normal) {
* {
font-family: 'FooV', 'Foo-Fallback', sans-serif;
}
} Links for defining and previewing Unicode ranges: |
Related: #20365 |
Preloading directives for <!-- if we're loading from some other place -->
<link rel="preconnect" href="https://foo.com" crossorigin>
<!-- Prefetching the binary before the stylesheet -->
<link rel="preload" href="https://foo.com/bar.woff2" as="font" type="font/woff2" crossorigin>
<!-- Typography-related CSS should be requested after -->
<link rel=stylesheet" href="typography.css"> |
It is necessary to find and propose a solution to avoid FOUT(Flash of Unstyled Text) for apps and editor.
Possible solutions:
The text was updated successfully, but these errors were encountered: