Notice This is a beta feature offered by Google. Also this is automatic translation, which means the results are often inacurate and/or hilarious. Enjoy.

ARCHIVES /  RSS
Blog

A Firebug improvement idea

h3  ~  25 Sep 2008, 18:28  –  5 comments

Today I saw this blog post on reddit. It's something that crossed my mind at some point in my life, but I never tried to do it. Aaron implemented it using PHP, but I think it could be fairly easy to implement it in JavaScript. However, I'll keep that for another post.

Finding incompatibilities in CSS can be useful, but I think of another thing for which there is no ready made solutions available is finding which selectors are not used.

Usually StyleSheets just grow with time. Of course we try to keep it clean and remove unused code blocks as they are deprecated, but there's always those on which you stop and ask yourself "do I still use that ?" and you don't touch it just to be sure.

The basic concept with jQuery is pretty straight foreward since jQuery works with CSS selector:

$.each(document.styleSheets[0].cssRules, function() { 
    if ($(this.selectorText).length < 1) { 
        console.log('Unused: %s', this.selectorText);
    } 
});

It didn't take too long before I started to draft in my mind a jQuery plugin idea which would allow to "debug" and optimize CSS.

However I came to the conclusion that it was not such a great idea, it should instead be a Firebug feature.

So John, here's my wish list for Christmas (behold my limited Gimp skills):

  • Display unused selector blocks grayed
  • Display non-standard selector another color

post a comment Comments

Great idea!

I think that displaying unused CSS blocks would be particularly handy, because a CSS file can evolve to a point where you're just not sure if you're using all the bits in there any more.

Dave Rolsky ~ September 25, 2008 at 7:09 p.m.

@Dave Rolsky

Thanks, but I've just realized that it would probably more practical to just strike-trough the selector since they can refer to more than one element, class or id by using a coma.

h3 ~ September 25, 2008 at 8:17 p.m.

It's a great idea. As a firebug plugin it would be even better.

Alecu ~ September 26, 2008 at 7:18 a.m.

je crois que ton flux rss ne fonctionne plus depuis janvier :(

lqd ~ October 1, 2008 at 11:14 a.m.
h3 ~ October 2, 2008 at 1:18 a.m.
Copyrighted stuff .. u know.