Expand externalization of data: URLs in @font-face rules#2079
Merged
westonruter merged 4 commits intodevelopfrom Apr 7, 2019
Merged
Expand externalization of data: URLs in @font-face rules#2079westonruter merged 4 commits intodevelopfrom
westonruter merged 4 commits intodevelopfrom
Conversation
amedina
reviewed
Apr 7, 2019
amedina
approved these changes
Apr 7, 2019
Member
amedina
left a comment
There was a problem hiding this comment.
6% reduction in CSS size is a good gain. Ship it.
Member
Author
|
Good gain or good loss? 😉 |
amedina
approved these changes
Apr 7, 2019
3 tasks
3 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.
Twenty Nineteen has quite a bit of CSS, and part of it is due to the
NonBreakingSpaceOverridefont which is inlined as adata:URL. While this font was temporarily removed from the frontend styles in WordPress/twentynineteen#623 it was added back in WordPress/twentynineteen#670 as @kjellr notes in WordPress/twentynineteen#623 (comment):In AMP it turns out to be a big deal, because of the 50KB budget for
style[amp-custom]. Thedata:-URL inlined WOFF2 and WOFF files account for 3KB, which is 6% of the budget. This is a lot especially for something that definitely not required, per above.The AMP plugin already has built-in support for externalizing
data:URLs for font files in the case of Dashicons. That externalization depended on one of the fontsrcURLs to be an external file so that it could guess where to find the external file version of thedata:-encoded font. For example,dashicons.csshas:Based on this, the plugin can successfully guess that woff font encoded in the
data:URL would probably be located at../fonts/dashicons.woffsince the TrueType version is located at../fonts/dashicons.ttf.That's all well and good. But what if there are no non-
data:URLs defined? This is the case for Twenty Nineteen. It contains:The AMP plugin doesn't know where to locate the woff2 and woff files.
It turns out that even though Twenty Nineteen doesn't reference these files externally, they are present in the theme at:
fonts/NonBreakingSpaceOverride.woff2fonts/NonBreakingSpaceOverride.woffWith this in mind, the plugin can expand its guessing of the external file locations based on the name in the
font-family.As an added touch for performance, when a
data:URL is converted to an external URL, the@font-facegets afont-display: swap. This prevents the font's loading from blocking the rendering of the text.Before:
style.cssat 42KBAfter:
style.cssat 39KBSee #1492.