-
Notifications
You must be signed in to change notification settings - Fork 382
Description
To build upon existing style sanitizer, I have to maintain a fork due to lack of hooks. These hooks would be especially useful for the tree shaker.
amp_selector_should_includewould be a great hook for $should_include to allow or remove classes in the tree shaking process. Something like:
$should_include = apply_filters( 'amp_selector_should_include', $should_include, $selector, $parsed_selector );
I am using this to write a custom check to strip out few more classes that linger around despite being unnecessary, like some multi-class selectors such as .something.else remaining even when unused. This filter can essentially whitelist classes that might be wrongly removed, or blacklist classes that are unnecessarily preserved.
- Or more importantly, allowing filtering of CSS parts would be great. Just before
$sheet_sizeis calculated, a filter such as following could be great:
$stylesheet = apply_filters( 'amp_stylesheet_part', $stylesheet );
Using this filter, a plugin/theme can do further processing to remove CSS as necessary. I am using it to filter empty @media and @support blocks but it could also be used for addition or further removal.
P.S. thanks for the tremendous effort on v1.0. I have been using the beta in production and have no complaints so far.