ampproject / ampproject/amphtml

Automatically add @font-face for custom whitelisted Google fonts via AMP CDN.

Open
#23,151 5 comments 2 reactions 0 assignees View on GitHub
P3: When Possible Stale Type: Feature Request WG: caching
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

Google Fonts and certain whitelisted fonts are extremely popular and widely used. There are two main ways to load them:

1. via css ``````

2. via @font-face

The CSS option is render blocking and causes slowness. The @font-face option is the preferred and super-fast. However, using @font-face option involves adding the `src` which becomes cumbersome when you are using multitude of fonts.

Proposal:
When AMP pages are hosted on AMP CDN,

1. provide a way to automatically parse the rel="stylesheet".
2. discover the white-listed fonts that are being used.
3. inject the fonts directly from the reference stylesheet as @font-face.
4. Don't count the @font-face included by this approach towards the 50KB CSS limit.

Future:
1. Extend the above method towards all fonts, whitelisted and otherwise.

Advantage:
Font's are render blocking and this approach can speed up things while maintaining UI/UX consistency and with less code.

Update: According to https://github.com/ampproject/amphtml/issues/11249, fonts aren't render blocking, however, lightspeed and PSI both suggest to use @font-face instead of the above link-href approach.

Assuming Lightspeed/PSI is incorrect, should we open a ticket on their side?

Contributor guide

Open the contributing guide

Research direction

The issue names no source files or tests. Start by reviewing AMP CDN handling of stylesheet links and the discussion in issue #11249; define the whitelist, font injection behavior, and CSS-limit accounting before implementation. Done means the agreed behavior is specified and covered for supported fonts.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript
Domain
frontend, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.