<Slushman />

unsplash-logo dylan nolte

Results for the Underscores Stylesheet

Published Oct 28, 2016

In the previous posts in the Parker series, we optimized the stylesheet for the _s starter theme. We also used hooks and functions to customize the WordPress menus. In this post, we will compare our goals and the results we achieved using Parker. Here were our the goals:

Now, lets compare our baseline to our final results:

Baseline

Final Results

Comparison

These lists are helpful, but lets take a look at each optimization and compare the numbers.

Stylesheet Size

Stylesheet size went from 15432kb to 14405kb. That’s an over 1kb reduction! While it’s “only” a 1kb reduction, we’re working with a starter theme. Our future projects benefit by having a smaller starting stylesheet.

Total Selectors

Total Selectors reduced from 280 to 240. This is not a drastic reduction, but fewer selectors mean styles are easier to understand. Your future self will thank you!

Total Identifiers

Total Identifiers reduced from 508 to 350. This is a much larger reduction. Reducing the number of identifiers makes the stylesheet easier to understand. Styles are also easier to override, if necessary.

Selectors Per Rule

Selectors Per Rule reduced from 2.08955223880597 to 1.791044776119403. Ideally, that final number would just be one so styles apply to a single class.

Identifiers Per Selector

Identifiers Per Selector reduced from 1.8285714285714285 to 1.475. This should also be, ideally, one. Selectors should apply to a single class. However, pseudo classes like hover or focus count against you here, making this difficult to avoid.

Specificity Per Selector

Specificity Per Selector reduced from 10.446428571428571 to 8.566666666666666. The ideal is up for debate and depends on your CSS methodology. Parker favors the lowest possible specificity. However, BEM and other CSS methodologies favor using classes for everything. Meaning the lowest possible score would be 10. Either way, reducing specificity makes stylesheets easier to understand and maintain. The “ideal” should be whatever works best for you.

Top Selector Specificity

Top Selector Specificity score reduced from 120 to 30. This is not a vital metric, but still a good one. This reduction involves a major break away from how _s styles things by default though. The most specific selector they use is for the skip-to-content link target. I asked why this was so specific and it appears they want the higher-level specificity.

Total ID Selectors

The Total Id Selectors reduced from 1 to 0. This is the same thing as above. The skip link target styling uses an ID. If you change this one style, you lower this metric to 0. You also drastically reduce the Top Selector Specificity at the same time.

Wrapping Up

Those are some pretty good results for a starter theme stylesheet. You’ll see much better results with a fully-developed theme. Having done all this work though, what does it all mean?

Reducing the stylesheet size helps the site load faster. Each browser request can only return 14kb at a time. Our newly optimized stylesheet, now at 14.4kb, is almost small enough to fit into a single request.

We’ve made the stylesheet easier to read by eliminating the longer selectors, also making it easier to maintain.

Finally, we’ve added more reusable classes and made the remaining rules less specific. In future projects, one would create only reusable classes and use WordPress hooks to style elements directly.

I plan to submit pull requests to the _s repo based on some of these tweaks. Hopefully, some of these changes will already exist in future versions of _s. I highly recommend running Parker on your finished stylesheets. Parker doesn’t solve everything but rather shows what needs improving.

Parker integrates nicely into Gulp. My gulpfile runs Parker after processing my SASS files, then displays a simple report in the command line. Let me know how Parker is changing your stylesheets and/or development process!

Share this post!

Check out these related posts:

Installing Parker

If you want to use the CSS analysis tool, Parker, you first have to install it and set it up. Here's the six step process.

Creating a Baseline for Parker

In order to optimize the Underscores stylesheet using the CSS tool Parker, we need to start by creating a baseline, so we can compare the changes.

Simplifying WordPress Menu Styling

Using results from the CSS Tool Parker, you can simplify the WordPress menu styling with a combination of custom classes and a menu walker.

Parker and WordPress Menus

Using the CSS tool Parker can help you fix your theme's menu styling. Learn the filters you'll need to make your WordPress menu styling simpler.