ampproject / amp-wp

Enable AMP on your WordPress site, the WordPress way.
https://wordpress.org/plugins/amp/
GNU General Public License v2.0
1.79k stars 383 forks source link

Explore use of Symfony's CssSelector to do deeper tree shaking #2102

Closed westonruter closed 2 years ago

westonruter commented 5 years ago

Symfony has a CssSelector component which can be used to convert a CSS selector to an XPath expression. This in theory could be used to do evaluate a given selector against the document to determine whether it applies. This could shake quite a bit of CSS that we currently don't consider, for example selectors with multiple class names. Special care would be needed to account for selectors that interact with elements in an AMP document that are dynamically modified at runtime.

westonruter commented 5 years ago

Alternatively, we could still use the CSS selector parser to construct the XPath expressions with an awareness of which parts are dynamic in an AMP document. Note also:

https://github.com/ampproject/amp-wp/blob/4a78a2df53b00b9794b66406c9908d94a47f610b/includes/sanitizers/class-amp-style-sanitizer.php#L1510-L1513

westonruter commented 5 years ago

This is not going to be so straightforward because the library requires PHP 7.1. The plugin currently requires PHP 5.4, though we should soon update to 5.6 like core. But this won't be feasible until PHP 7.1 is the minimum supported version. This could happen in core by the end of 2019, so we might be able to do it at that time.