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

new-audit(unminified-css): identifies savings from unminified CSS #4127

Merged
merged 6 commits into from
Jan 5, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Dec 27, 2017

closes #3459

don't squash this one please as removing no-old-flexbox is a relatively atomic commit :) I'll manually rebase before merge

I'm honestly not a huge fan of this audit, I'm not sure it would pass our criteria and it was quite difficult to find a site where it was triggered at all as the usual suspects were fine (CNN, The Verge, etc).

A relatively bloated Wordpress theme (http://theme.weartstudio.eu/thewire/) finally got it but only with ~40ms estimated savings, the production minified version of bootstrap only saves you 2KB after gzip which is below our regular threshold.
image

The overall approach is similar to unminified javascript, count the % of the content that is meaningful which in this case excludes whitespace and comments. It's just that the volume of CSS is usually quite a bit lower than JS on sites. In the process I had to revive the styles gatherer and kill the no-old-flexbox which needed parsed content that made it slow.

realization that needs to be addressed: the styles gatherer is basically useless on its own because every time you turn on/off the CSS domain all the stylesheet ids change, so we might as well just base the audit on network records and leave the old flexbox cleanup for another time

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

as mentioned, i'm a fan of including this audit even if it rarely shows up as an important opportunity.

good to help devs understand that this optimization isn't really worth their time.

for (let i = 0; i < content.length; i++) {
const char = content.charAt(i);
const nextChar = content.charAt(i + 1);
const chars = char + nextChar;
Copy link
Member

Choose a reason for hiding this comment

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

might be worth doing perf testing of these.

whats the runtime cost of this audit on a decent size site?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

test1 https://jsperf.com/charat-master/1 proves winner is

const chars = content.substr(i, 2)
const char = chars.charAt(0)

equals is 100x faster than regex for those two lines too 👍

total runtime on sites with lots of css (i.e. that actually trigger savings) was ~50ms

@patrickhulce
Copy link
Collaborator Author

I reverted the commit that messes with styles gatherer and just stuck this in full config for now. My plan is to immediately followup with a PR that brings both unused-css and unminified css into the default config 🎉

@GoogleChrome GoogleChrome deleted a comment from patrickhulce Jan 4, 2018
@paulirish paulirish merged commit 622b9c2 into master Jan 5, 2018
@paulirish paulirish deleted the css_minification branch January 5, 2018 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audit: Resources are served minified
2 participants