-
Notifications
You must be signed in to change notification settings - Fork 1k
Output woff and ttf font-face references only with explicit compatibility setting #5108
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
Conversation
@@ -60,6 +60,7 @@ exports.test = series( | |||
*/ | |||
exports.buildSpriteStandalone = buildSpriteStandalone; | |||
exports.buildSprite = buildSprite; | |||
exports.compileSass = compileSass; |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to simplify development
packages/uswds-core/src/styles/functions/font/font-sources.scss
Outdated
Show resolved
Hide resolved
packages/uswds-core/src/styles/functions/font/font-sources.scss
Outdated
Show resolved
Hide resolved
packages/uswds-core/src/styles/variables/project-font-face-filetypes.scss
Outdated
Show resolved
Hide resolved
packages/uswds-core/src/styles/variables/project-font-face-filetypes.scss
Outdated
Show resolved
Hide resolved
Since the compatibility choice is binary (support older browsers or only modern browsers), we don't need granularity in our font key. We only need "output all formats" or "output only modern formats". This simplifies the code to have a simple `true`/`false` for a `compatibility` key
src: url(#{$file-path}.woff2) format("woff2"), | ||
url(#{$file-path}.woff) format("woff"), | ||
url(#{$file-path}.ttf) format("truetype"); | ||
src: font-sources($file-path); |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left this as a function since even though the logic is simple now, there may be some more complex logic we'll want to explore around variable fonts when we add that support in the future
This is ready for review. I'll update the website with documentation once the review progresses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I've tested:
-
Default fonts (
woff2
) -
Setting
$theme-font-browser-compatibility: true
. Compiled CSS shows all variants. -
Loading custom font without issues (Only had woff2 available).
$theme-font-serif-custom-src: ( dir: "young-serif", roman: ( 100: false, 200: false, 300: false, 400: "YoungSerif-Regular", 500: false, 600: false, 700: false, 800: false, 900: false, ) ), $theme-typeface-tokens: ( "young-serif": ( "display-name": "young-serif", "cap-height": 364px, "stack": "Georgia" ) ), $theme-font-type-serif: "young-serif",
Summary
Output only the modern woff2 font format, unless you need compatibility. Now we output only the
woff2
webfont format with our default settings. Since we no longer support IE11 and other old browsers, we no longer need to serve these file formats. Teams that need this support can activate it with a new setting:$theme-font-browser-compatibility: true
.Breaking change
This is not a breaking change unless your project is actively supporting IE11. If your project supports IE11, you'll want to add
$theme-font-browser-compatibility: true
to your settings.Related issue
Fixes #5103
Preview link
Preview →
Problem statement
In the modern browser landscape, self-hosted custom fonts no longer need
woff
, andttf
fonts. If teams need to support IE11, they should be able to output these additional formats, but most teams should not serve them. See more information at web.dev and in the original issue.Solution
No longer output all three file formats by default. Provide a setting to ouput them only for teams that need it.
Alternatives
We could make compatibility mode on by default.
Testing and review
Generate USWDS CSS and check the
@font-face
rules. They all should include a line likeGenerate USDS with
$theme-font-browser-compatibility: true
in settings. You should see@font-face
rules with all three file formats in thesrc
property:Documentation
Add font-face update documentation #2022