Output woff and ttf font-face references only with explicit compatibility setting#5108
Merged
thisisdano merged 19 commits intorelease-3.4.0from Mar 9, 2023
Merged
Output woff and ttf font-face references only with explicit compatibility setting#5108thisisdano merged 19 commits intorelease-3.4.0from
thisisdano merged 19 commits intorelease-3.4.0from
Conversation
thisisdano
commented
Mar 8, 2023
| */ | ||
| exports.buildSpriteStandalone = buildSpriteStandalone; | ||
| exports.buildSprite = buildSprite; | ||
| exports.compileSass = compileSass; |
Contributor
Author
There was a problem hiding this comment.
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
thisisdano
commented
Mar 9, 2023
| src: url(#{$file-path}.woff2) format("woff2"), | ||
| url(#{$file-path}.woff) format("woff"), | ||
| url(#{$file-path}.ttf) format("truetype"); | ||
| src: font-sources($file-path); |
Contributor
Author
There was a problem hiding this comment.
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
Contributor
Author
|
This is ready for review. I'll update the website with documentation once the review progresses. |
mejiaj
approved these changes
Mar 9, 2023
Contributor
mejiaj
left a comment
There was a problem hiding this comment.
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",
Merged
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Output only the modern woff2 font format, unless you need compatibility. Now we output only the
woff2webfont 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: trueto your settings.Related issue
Fixes #5103
Preview link
Preview →
Problem statement
In the modern browser landscape, self-hosted custom fonts no longer need
woff, andttffonts. 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-facerules. They all should include a line likeGenerate USDS with
$theme-font-browser-compatibility: truein settings. You should see@font-facerules with all three file formats in thesrcproperty:Documentation
Add font-face update documentation #2022