ENH: tree-shake unused AMP CSS custom properties + trim @font-face to woff2 - #14234
Open
hotinglok wants to merge 20 commits into
Open
ENH: tree-shake unused AMP CSS custom properties + trim @font-face to woff2#14234hotinglok wants to merge 20 commits into
hotinglok wants to merge 20 commits into
Conversation
… woff2 [copilot]
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to further reduce AMP article inline CSS size (to stay under AMP’s 75KB amp-custom limit) by introducing two new CSS post-processing utilities: (1) tree-shaking unused :root custom properties and (2) trimming @font-face src lists to woff2-only.
Changes:
- Added
treeshakeCssCustomPropertiesutility (+ unit tests + README) to remove unused:rootcustom properties, including transitive dependency retention. - Added
trimFontFaceSourcesToWoff2utility (+ unit tests + README) to keep onlywoff2(andlocal()) in@font-face src. - Updated
_document.page.tsxto replace the sharedoptimiseCssPrefixesimport with a new inline regex-based implementation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ws-nextjs-app/utilities/trimFontFaceSourcesToWoff2/README.md | Documents the new woff2-trimming utility. |
| ws-nextjs-app/utilities/trimFontFaceSourcesToWoff2/index.ts | Implements @font-face src trimming logic. |
| ws-nextjs-app/utilities/trimFontFaceSourcesToWoff2/index.test.ts | Adds unit tests for woff2 trimming behavior. |
| ws-nextjs-app/utilities/treeshakeCssCustomProperties/README.md | Documents the new custom-property tree-shaker. |
| ws-nextjs-app/utilities/treeshakeCssCustomProperties/index.ts | Implements :root custom-property tree-shaking with dependency closure. |
| ws-nextjs-app/utilities/treeshakeCssCustomProperties/index.test.ts | Adds unit tests for custom-property tree-shaking behavior. |
| ws-nextjs-app/pages/_document.page.tsx | Inlines a regex-based optimiseCssPrefixes implementation in the document rendering path. |
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.
Builds on #14229. Further reduces the size of the inline
<style amp-custom>on AMP article pages to keep well under AMP's 75KB CSS limit. This is also applied to lite pages.Adds two CSS optimisation passes for the AMP/Lite inline <style> and wires them into _document:
@font-facesrclists down to their woff2 source only. Service themes ship each face with a woff2 source plus a legacy wofffallback, e.g.
Impact and Testing
Against the real
newstheme (latin, 4 font faces, ~6.1KB theme CSS) with the actual transforms:Running the following script in browser console to check the
ampCustomsize:On latest (as of 05/08/2026): 61822 bytes
On this branch: 57252 bytes
Tree-shake is the dominant lever: components consume theme colours via compile-time SCSS
$variables (literal hex), so the theme's--brand-*/palette custom properties have effectively novar()consumers in the rendered CSS and are safely removed.