Skip to content

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

Merged
merged 19 commits into from
Mar 9, 2023

Conversation

thisisdano
Copy link
Contributor

@thisisdano thisisdano commented Jan 24, 2023

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, and ttf 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 like

src:url(../fonts/roboto-mono/roboto-mono-v5-latin-700.woff2) format("woff2");

Generate USDS with $theme-font-browser-compatibility: true in settings. You should see @font-face rules with all three file formats in the src property:

src:url(../fonts/roboto-mono/roboto-mono-v5-latin-700.woff2) format("woff2"), url(../fonts/roboto-mono/roboto-mono-v5-latin-700.woff) format("woff"), url(../fonts/roboto-mono/roboto-mono-v5-latin-700.ttf) format("truetype");

Documentation

Add font-face update documentation #2022

@thisisdano thisisdano marked this pull request as draft January 24, 2023 20:48
@thisisdano thisisdano changed the base branch from develop to release-3.4.0 March 8, 2023 19:51
@@ -60,6 +60,7 @@ exports.test = series(
*/
exports.buildSpriteStandalone = buildSpriteStandalone;
exports.buildSprite = buildSprite;
exports.compileSass = compileSass;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to simplify development

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 thisisdano changed the title Allow using subset of supported filetypes for font-face rules Allow using only woff2 for font-face rules Mar 8, 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);
Copy link
Contributor Author

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

@thisisdano thisisdano changed the title Allow using only woff2 for font-face rules Output woff and ttf font-face references only with explicit compatibility setting Mar 9, 2023
@thisisdano thisisdano requested a review from mejiaj March 9, 2023 00:08
@thisisdano thisisdano marked this pull request as ready for review March 9, 2023 00:08
@thisisdano
Copy link
Contributor Author

This is ready for review. I'll update the website with documentation once the review progresses.

Copy link
Contributor

@mejiaj mejiaj left a 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).

    image

    $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",

@thisisdano thisisdano mentioned this pull request Mar 9, 2023
@thisisdano thisisdano merged commit e4423b1 into release-3.4.0 Mar 9, 2023
@thisisdano thisisdano deleted the dw-update-fontface branch March 9, 2023 19:05
@mejiaj mejiaj mentioned this pull request Mar 16, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USWDS - Feature: WOFF2 only fonts
2 participants