-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
ee27847
to
6eefc26
Compare
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 🎉 |
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.

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