Skip to content
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

Extend CSS tree shaking to remove selectors for non-existent IDs and elements #1142

merged 2 commits into from May 11, 2018


3 participants
Copy link

westonruter commented May 11, 2018

If a CSS selector contains a reference to an ID, like #subscribe-email input { ... } and there is no element with the ID of subscribe-email in the document, then this CSS rule should be removed. Additionally, if a CSS selector includes a reference to a tag name for an element that doesn't exist in the document, then this CSS selector should also be removed from the document.

On Twenty Fifteen without these changes, the CSS is 42421 bytes. With this branch, the CSS is 35114 bytes. So about 20% smaller.

This also removes trailing semicolons from rules to save additional bytes.

westonruter added some commits May 11, 2018

@westonruter westonruter added this to the v1.0 milestone May 11, 2018

@westonruter westonruter requested a review from kienstra May 11, 2018

Copy link

kienstra left a comment


Hi @westonruter,
Thanks, this looks good. It really helps to remove rules where the selector has an ID or tag that's not in the document.

There were similar decreases in CSS size when testing with Twenty Sixteen in Paired Mode. Before, there were 37005 bytes of CSS, and with this PR there were 30747 bytes.

@westonruter westonruter merged commit d2b2c2d into develop May 11, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@westonruter westonruter added this to Ready for QA in v1.0 May 31, 2018

@kienstra kienstra moved this from Ready for QA to Ready for Merging in v1.0 Jun 6, 2018

@westonruter westonruter deleted the add/extended-tree-shaking branch Jul 5, 2018

@kienstra kienstra moved this from Ready for Merging to In Production in v1.0 Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.