Live data from Hacker News

UnCSS: Remove unused styles from CSS

github.com

31–40 of 50 posts

Re: UnCSS: Remove unused styles from CSS

#31

Am I missing something? UnCSS has been for about 3 years now. http://bit.ly/uncss by addyosmani

I guess this is being downvoted because he links to the wrong repo (i.e. the grunt edition of the same project) but the point seems fair. I've been using unCSS about 2 years so it is interesting that this discussion is happening now and that people seem surprised by its existence. Perhaps just a symptom of too much JS everything.

Re: UnCSS: Remove unused styles from CSS

#32
post #6

I've been hoping someone would write a similar tool, but using a browser, so that I could run a webapp, click around (using a checklist, to cover all of the views) and get a resulting list of used CSS rules from the browser. That would have the advantage of supporting complex webapps written in any language/environment.

States can quickly become complex. Like styles for a logged in user with a 3-years-membership badge or styles for a placeholder that only new users see. Or styles for a CMS module that is currently not in use (e.g. for open positions in a company). I wonder what the least used, yet still used CSS is I ever wrote (relative to project traffic). Maybe some feature a Client requested, I knew he would never really use, bu…

It might be hard to do for an existing site of considerable size, but for new sites it could be done incrementally as features are added.

Re: UnCSS: Remove unused styles from CSS

#33
post #6

I've been hoping someone would write a similar tool, but using a browser, so that I could run a webapp, click around (using a checklist, to cover all of the views) and get a resulting list of used CSS rules from the browser. That would have the advantage of supporting complex webapps written in any language/environment.

Etsy did something like that, but on the production site.

Every visitor had a small probabillity it would run the code, and after a couple of million visitors, they had a pretty good idea of what styles were unused.

Re: UnCSS: Remove unused styles from CSS

#34
post #33
post #6

I've been hoping someone would write a similar tool, but using a browser, so that I could run a webapp, click around (using a checklist, to cover all of the views) and get a resulting list of used CSS rules from the browser. That would have the advantage of supporting complex webapps written in any language/environment.

Etsy did something like that, but on the production site. Every visitor had a small probabillity it would run the code, and after a couple of million visitors, they had a pretty good idea of what styles were unused.

That would actually solve the use case above (hidden styles triggered by Javascript).

A large user base would give you decent coverage.

Re: UnCSS: Remove unused styles from CSS

#35
post #11

Have used tools like this before, and invariably end up accidentally stripping styles from an component with a dynamically assigned className or something equally silly. It's such a hard problem to solve and the Stylesheet Snowball is one of the most frustrating pieces of technical debt a large site can pick up. It makes me wonder if scoped CSS modules, despite fundamentally breaking CSS with their hyper specific hyb…

My experience with CSS modules is that it has the same problems, just at a smaller scale. And because of the local scope I also see a lot more code duplication. It also doesn't play very well with global CSS libraries like bootstrap.

Re: UnCSS: Remove unused styles from CSS

#38
post #2

I wonder what the performance increase would be of loading one big CSS file on the first page load and serving from local cache from then on, vs loading a smaller but different CSS file for each page you visit. My impression is that number of requests is a more critical optimization than file size (at least when serving CSS sized files)

Serving the page with inlined CSS also has the compression benefit of many html ids and classes being repeated in the CSS.

Re: UnCSS: Remove unused styles from CSS

#39
post #11

Have used tools like this before, and invariably end up accidentally stripping styles from an component with a dynamically assigned className or something equally silly. It's such a hard problem to solve and the Stylesheet Snowball is one of the most frustrating pieces of technical debt a large site can pick up. It makes me wonder if scoped CSS modules, despite fundamentally breaking CSS with their hyper specific hyb…

For me, BEM takes much of the pain out of reusing and (especially) refactoring big CSS.

Re: UnCSS: Remove unused styles from CSS

#40
post #6

I've been hoping someone would write a similar tool, but using a browser, so that I could run a webapp, click around (using a checklist, to cover all of the views) and get a resulting list of used CSS rules from the browser. That would have the advantage of supporting complex webapps written in any language/environment.

There is one built into Chrome's dev tools, in the audit tab: http://imgur.com/a/Va2d0

It is, though, limited to the context of a single page. You can't browse several pages and then see what the net unused css is.

I believe, though, extensions can talk to dev tools, so there's some plausible way to extend it.

Post reply on HN