ampproject / ampproject/amp-toolbox
Optimizer: Add transformer to automatically add font-display:optional to (known) non-icon fonts
- Dominant language
- HTML
- Stars
- 459
- Forks
- 242
- PR merge metrics
- No merged PRs in 30d
Description
Something that we're finding a lot in WordPress (e.g. https://github.com/ampproject/amp-wp/issues/6036 and [support topic](https://wordpress.org/support/topic/fid-lcp-and-cls-issue/#post-14385558)) is that many sites use fonts and they fail to use `font-display:optional`. This is reported both by the Lighthouse [`font-display`](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/audits/font-display.js) audit and the Pixi [`fontDisplay`](https://github.com/ampproject/amp-toolbox/blob/main/packages/page-experience/lib/checks/fontDisplay.js) check:
> 
> 
In addition to skipping the `font-display` check specifically for icon fonts (#1218), what if we have a transformer which proactively _adds_ `font-display:optional` for fonts which are known to be non-icon fonts? For Google Fonts, there's only a [few](https://fonts.google.com/?query=icons) [icon](https://fonts.google.com/icons) fonts so I believe we can easily compile a list of such fonts to exclude for automatic “optionalification”.
The thing is that `font-display:optional` can make the first load of a website look _bad_ if proper fallbacks are not used, so such a transformer likely cannot be applied by default. Nevertheless, it would be great to have such a transformer available so that you could have a way to resolve the audit failure just by enabling a transformer rather than having to hack the underlying code (which may not be feasible).
Contributor guide
Research direction
Start by reviewing the Lighthouse and Pixi font-display checks linked in the issue, along with the icon-font exception in #1218. Then locate the optimizer transformer entry point and how Google Fonts are identified; done means an opt-in transformer adds font-display:optional only for known non-icon fonts while excluding icon fonts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css
- Domain
- performance, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100