You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to be able to reliably excise !important from styles (#927), we need a proper CSS parser to be able to parse the rules so that higher-specificity selectors can be used instead of !important.
Additionally, a CSS parser used in conjunction with sanitization where the document has been output buffered and parsed into a DOM tree will allow us to strip out all CSS rules from the document that are not relevant to the current page, such as by checking to see if a rule references a class name that does not exist on the current page.
This will also address minification in #688. Class names could be minified in the CSS rules as well as in the document's elements that have the class attributes.
Current work can be seen in the add/css-parser branch. The idea is to use the same phpegjs library that is being used by Gutenberg to parse blocks. The PEG grammar needs to be written for CSS. The grammar currently in the branch needs to be simplified to reduce the granularity. We don't need each token separately parsed for a given selector, but rather just the entire selector string as a whole.
As part of this we should probably augment \AMP_Theme_Support::ensure_required_markup() to ensure the amp-boilerplate is present. Likewise, the way that AMP_WP_Styles waits to output styles should be removed in favor of just outputting them right away to then allow the sanitizer to collect them. The CSS sanitizer can then be responsible actually for adding the style[amp-custom] to the head.
This will supersede and incorporate #610 to switch from blacklist to whitelist. It will also need to improve the approach to scrubbing !important in #927. See #927 (comment).
The text was updated successfully, but these errors were encountered:
In Twenty Fifteen, on a single page that is fully populated with all embeds, widgets, and has a comment in it, the style.css (97KB) coverage as reported by Chrome is:
So if we were able to delete all of the unused bytes, the the CSS would be below 50KB.
Additionally, if the CSS were also minified with all whitespace and comments stripped, then this would bring the initial size from 97KB down to 77KB.
In order to be able to reliably excise
!important
from styles (#927), we need a proper CSS parser to be able to parse the rules so that higher-specificity selectors can be used instead of!important
.Additionally, a CSS parser used in conjunction with sanitization where the document has been output buffered and parsed into a DOM tree will allow us to strip out all CSS rules from the document that are not relevant to the current page, such as by checking to see if a rule references a class name that does not exist on the current page.
This will also address minification in #688. Class names could be minified in the CSS rules as well as in the document's elements that have the
class
attributes.Current work can be seen in the
add/css-parser
branch. The idea is to use the same phpegjs library that is being used by Gutenberg to parse blocks. The PEG grammar needs to be written for CSS. The grammar currently in the branch needs to be simplified to reduce the granularity. We don't need each token separately parsed for a given selector, but rather just the entire selector string as a whole.As part of this we should probably augment
\AMP_Theme_Support::ensure_required_markup()
to ensure theamp-boilerplate
is present. Likewise, the way thatAMP_WP_Styles
waits to output styles should be removed in favor of just outputting them right away to then allow the sanitizer to collect them. The CSS sanitizer can then be responsible actually for adding thestyle[amp-custom]
to thehead
.This will supersede and incorporate #610 to switch from blacklist to whitelist. It will also need to improve the approach to scrubbing
!important
in #927. See #927 (comment).The text was updated successfully, but these errors were encountered: