5 ms·
Is there a good CSS minifier which looks at the CSS as well as the HTML, and shortens class names automatically? In most cases I don't really care what the cla
by metafunctor 13y ago
Is there a good CSS minifier which looks at the CSS as well as the HTML, and shortens class names automatically? In most cases I don't really care what the class names are in the final HTML, as long as they match up with the CSS.
I realize there are a lot of things that could go wrong, such as
* correlating the HTML and CSS for an entire site instead of just one page
* dealing with third party dependencies that require certain class names to be used
Just wondering if there's any work already done with this approach.
- columbo 13y agoI don't think there's anything that will change the class names, but there are minifiers http://yui.github.io/yuicompressor/css.html http://yui.github.io/yuicompressor/css.html Changing the class names would be difficult as it wouldn't pick up any dynamic class names, like var className = 'user_' + user.getState(); //'user_deleted' or 'user_active'
- ygra 13y agoBut that's the same problem as minifying JS libraries already, where you have a set of public symbols that should not be altered. An exclusion list works well in that case where you could just put the class named that are for dynamic generation (you probably don't do that with all classes in the stylesheet).
- coldtea 13y agoNo need, because you can gzip compress, which will make even better savings than that (because it can also compress and save space taken by tags etc, not just class names).
- darkmighty 13y agoYou could do that and gzip though; it would probably yield some savings. An obfuscator generating code à la iocc efficiency would be quite neat (e.g. http://www.ioccc.org/2012/endoh1/endoh1.c http://www.ioccc.org/2012/endoh1/endoh1.c)
- coldtea 13y ago>You could do that and gzip though; it would probably yield some savings. Nope. That's classic non-engineer thinking. The same kind of thinking that does "optimization" without profiling. Let me introduce you to my friend: http://en.wikipedia.org/wiki/Diminishing_returns http://en.wikipedia.org/wiki/Diminishing_returns
- pbhjpbhj 13y ago"some savings" says the parent. A diminishing return is still a return.
- coldtea 13y agoAnd 0.0000000000001 of a dollar is still money. Yet it's meaningless to do anything about getting it...
- darkmighty 13y agoI can say the savings would probably be greater than the 50 bytes he saved on the domain name. Compressing is not magical, if you compress class names you're still storing at least one instance of each name plus overhead.