Skip to content
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

perf(cdr-fonts.css): Low-CLS fallback #178

Merged
merged 4 commits into from
Jul 2, 2024
Merged

perf(cdr-fonts.css): Low-CLS fallback #178

merged 4 commits into from
Jul 2, 2024

Conversation

caseycarroll
Copy link
Collaborator

Description

This change reduces the layout shift impact of font-display: swap. Font-face descriptors allow us to resize the fallback font to closely match the brand font that replaces it. This will improve the page loading experience for cold-cache visitors of REI.com.

I used Fontaine to automatically generate the font-face descriptors.

I added this new fallback to cdr-reset. Consumers of Cedar will need to explicitly add "Graphik fallback" and "Stuart fallback" to their font-family property. Considering that, I may need to add some documentation.

In the example, notice how the call to action moves as Stuart loads in. After adding the fallback font to the font-family property, the call to action no longer jumps as the font loads in.
https://github.com/rei/rei-cedar/assets/6683238/06b1a5d3-7ef2-4e79-b53d-84bcd339a635

Checklist:

Design:

  • Reviewed with designer and meets expectations

Cross-browser testing:

  • Chrome
  • Firefox
  • Edge
  • Safari
  • iOS
  • Android

Unit testing:

  • Sufficient unit test coverage (see unit test best practices for ideas)
  • Snapshot updates are explained with comment and reference the relevant source code change

A11y:

  • Meets WCAG AA standards

Documentation:

  • API docs created/updated
  • Examples created/updated

…n web fonts swap from fallback

This change reduces the layout shift impact of font-display: swap. Font-face descriptors allow us to
resize the fallback font to closely match the brand font that replaces it. This will improve the
page loading experience for cold-cache visitors of REI.com.
@caseycarroll
Copy link
Collaborator Author

Graphik and Stuart are variable fonts, yet they don't support italics (hence the separate font-face for their italic counterparts). We should see if there's an updated version of this variable font that supports italics. This would remove the additional italic font download for pages that use italics.

FontGoogles confirms Graphik and Stuart are variable fonts, but the only variation they support is "weight".

More on this: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide#italic

@benjag
Copy link
Contributor

benjag commented Feb 22, 2024

Don't worry about the failure, chromedriver just needs to be updated. I'll pull this in to a release branch and take care of it then

@benjag
Copy link
Contributor

benjag commented Feb 22, 2024

@caseycarroll Why do you think consumers will need to explicitly add the fallback fonts?

@caseycarroll
Copy link
Collaborator Author

@caseycarroll Why do you think consumers will need to explicitly add the fallback fonts?

I made this assumption before looking through microsites' font-family declarations. I assumed they manually set Stuart, Georgia, but that's not the case. They use the cdr-font-family-serif token.

Given that, it looks like I will need to make another PR on cedar-tokens to add these new fallbacks. https://github.com/rei/rei-cedar-tokens/blob/next/tokens/_options/font.json5

@benjag
Copy link
Contributor

benjag commented Feb 23, 2024

@caseycarroll Why do you think consumers will need to explicitly add the fallback fonts?

I made this assumption before looking through microsites' font-family declarations. I assumed they manually set Stuart, Georgia, but that's not the case. They use the cdr-font-family-serif token.

Given that, it looks like I will need to make another PR on cedar-tokens to add these new fallbacks. https://github.com/rei/rei-cedar-tokens/blob/next/tokens/_options/font.json5

Why don't we take this to slack so you can share those examples, microsites in most cases shouldn't be defining their own font-families, they should just be importing the cdr-fonts asset.

mhewson added a commit to rei/rei-cedar-tokens that referenced this pull request Jun 25, 2024
Adds new low-CLS fallback fonts introduced here: rei/rei-cedar#178
@caseycarroll
Copy link
Collaborator Author

caseycarroll commented Jun 27, 2024

Manual tests in climbers site caught layout shift, so I adjusted the fallbacks some more. Instead of using an automated approach, I went with a manual one. The end result is a simpler font-face ruleset and the discovery that Verdana is a better fallback for Graphik. Attaching some evidence.

Note that the nav does not have the fallbacks applied, so nav fonts still shift.

font.cls.control.mov
font.cls.test.mov

@sikhote sikhote changed the base branch from main to v15.1 July 2, 2024 16:48
@sikhote sikhote requested review from mhewson and sikhote July 2, 2024 16:50
@mhewson mhewson merged commit a9d70d5 into v15.1 Jul 2, 2024
@mhewson mhewson deleted the font-fallback-cls branch July 2, 2024 18:06
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.

4 participants