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
merged 2 commits into from
May 11, 2018

Conversation

westonruter
Copy link
Member

@westonruter 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 westonruter added this to the v1.0 milestone May 11, 2018
@westonruter westonruter requested a review from kienstra May 11, 2018 01:31
Copy link
Contributor

@kienstra kienstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

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
@westonruter westonruter deleted the add/extended-tree-shaking branch July 5, 2018 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants