-
Notifications
You must be signed in to change notification settings - Fork 385
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
Add a way for devs to enable css tree-shaking #1184
Comments
Thanks a lot, Chris.
That's right. It only kicks in if the CSS is over 50KB. The reason for conditionally enabling it is that there is a chance that some rules could be deleted from the stylesheet which actually are needed by the page at some point. Specifically when you have dynamic content being added to the page, such as via What's more is that when tree shaking is needed, by default it is going to be raised as a validation error and block the response from being served as AMP. What this means is that a user will need to opt-in to tree shaking the first time the error is encountered. There would be a programmatic way to automatically allow tree shaking via the brand new This filter however won't cause tree shaking to be invoked even when less than 50KB. There is a separate way you use to do that now, actually: add_filter( 'amp_content_sanitizers', function( $sanitizers ) {
$sanitizers['AMP_Style_Sanitizer']['remove_unused_rules'] = 'always';
return $sanitizers;
} ); The default value for the By changing it to “always” then this should cause tree shaking to always be performed. Give that a try. For the ampnews native AMP theme, this reduces CSS from 35KB to 13KB on the homepage. I've been considering that we should add a new AMP admin screen to manage settings regarding theme support, including:
Love it 😄 |
Hi Weston, Thanks for the detailed response and all the info :) Good to know. Thierry and I enabled it on the WineFolly dev install and saw about 20-30% reduction. I'm going to do a lot more testing / comparisons between the live and dev sites and will compile my findings in Google Sheet. I'm happy to share the results if you're interested. Having a place to configure the site specific amp stuff would be great. Happy to help out with testing where ever needed. Cheers, |
@devignerforhire FYI: As of v1.2 tree shaking will be done regardless of whether or not the original CSS is >50KB. See #2501. |
Hi guys,
First off let me start by saying how much we appreciate all the effort you guys are putting into the AMP for WP plugin - it's come a long way since the early beta version I first tested. We decided to take the plunge a few months ago to go full AMP and while it's come with it's own set of challenges, we're all pretty stoked with the outcome.
One of the things I've been dying to try out is the new css tree-shaking after seeing the demo in the Google IO preso. I believe the tree-shaking only kicks in after the 50kb limit has been exceded. It would be great if there was a way for devs to enable the tree-shaking by default? Obviously it would need to be tested in a staging environment first, but I'm really curious to how much it shaves off and at present I have no way of testing, since all the pages are below the 50kb limit.
It also opens the door to using front-end frameworks without incurring the extra bloat. Part of the challenge going full AMP was staying below the 50kb limit, which included replacing previously used UIkit components with vanilla css. Not that this is a bad thing, but having the option to still use front-end frameworks, while keeping the CSS at it's minimum would probably help with amp adoption by devs.
TIA,
Chris
Ps, we just launched https://winefolly.com, which is using the plugin in full AMP mode :)
The text was updated successfully, but these errors were encountered: