from Hacker News

What CSS minifiers also leave behind

by remy_luisant on 4/5/17, 6:57 AM with 108 comments

  • by josephg on 4/5/17, 7:49 AM

    The scientific notation one is a bug. Scientific notation isn't part of the CSS spec[1], and its not supported in all browsers.

    I learned this one the hard way a few months ago. We ran into a flexbox bug in one browser which we worked around by adding some-rule: 0.0000001px instead of 0px. However, our minifier collapsed that using scientific notation, which triggered a rendering issue in a different browser due to the out-of-spec CSS. The whole adventure left me feeling like I'd travelled back in time.

    [1] https://www.w3.org/TR/CSS21/syndata.html#numbers

  • by remy_luisant on 4/5/17, 7:51 AM

    Author here.

    Wow. #1 on HN. Wow.

    I'd usually hang around a bit more, but I'm really tired. I posted this past my midnight. 00:51 now, and I'm fading fast.

    Thanks for all the love, everyone. I'll come over tomorrow (12 hours from now, or so) to answer any questions or to pick up any corrections.

  • by cornedor on 4/5/17, 11:49 AM

    > I'm guessing that at nine nines that is pretty much a one anyway and it would not even change a single pixel on the screen.

    There used to be a bug with flex-wrap: wrap; where an element would wrap to the next line while it should have fit. You could fix it by instead using width: 25%; use width: 24.999999%; so it would be 25% on the screen but it would fix the problem so it didn't wrap to the next line. So you should look out with this.

  • by pasta on 4/5/17, 8:02 AM

    This looks like a fun project indeed!

    Unfortunately every time I read something about minifiers I got the feeling that people are optimizing the wrong problem.

    If you gzip data over the line it's already compressed. So minifying your stuff will only help you a little.

    The problem is on the client side. You can compress what you like but if the browser starts dropping frames because it has to compile/handle a ton of Javascript and CSS then minifying doesn't help the end user.

  • by replete on 4/5/17, 11:21 AM

    Don't mean to squash any enthusiasm, but these types of 1byte optimization savings don't really have real-world benefits due to over-the-wire compression like gzip and Brotli.

    A more interesting problem to solve, I think, is that of optimising CSS rules for browser rendering.

  • by Silhouette on 4/5/17, 10:39 AM

    Here's the same author's earlier post on this subject, "The missed chances: What minifiers leave behind", from last week:

    https://luisant.ca/css-opts-survey

  • by ovao on 4/5/17, 7:58 AM

    crass is doing some really wonderful stuff here -- I'm impressed!

    It's very interesting, however, that no one minifier is a consistent winner in these test cases, and that running CSS through multiple minifiers is actually, potentially, not all that crazy. (The very debatable real value in doing that notwithstanding.)

  • by mercer on 4/5/17, 10:13 AM

    I have a slightly-related question for those of you familiar with Webpack, css modules (css-loader/style-loader), and perhaps React as well: is there any reason not to use the 'default' approach where the styles for the components are simply inserted in a <style> (with unique, generated classnames)?

    To be clear: I don't mean philosophical reasons. I personally love letting javascript deal with the 'cascading' part and I don't have a problem with the idea of having styling embedded in the final page.

    What I'm curious about is if this has any kind of negative impact on performance, bandwidth, etc. Because the CSS is loaded on the component level, and because Webpack 2 does tree shaking, the page will be guaranteed to only contain CSS for the components that are on the page. And if I'd 'lazy-load' parts of the app, I'd get that benefit for my CSS as well with no extra effort.

    On the other hand, any benefits of having a compiled (and hopefully cached) bundle.css are offset by the need for an extra request for the css file, as well as the very likely situation that there'll be a bunch of unused css in that bundle.

    Am I missing some drawback to the above-mentioned approach?

  • by tambourine_man on 4/5/17, 12:18 PM

    Didn't know about all of those units. q, mm, cm… scientific notation?!

    Also didn't know one could use counters already. Browser support is great. I thought it was still under approval.

    Amazing stuff, thanks

  • by fleetfox on 4/5/17, 8:31 AM

    Can someone provide some hard numbers from real projects as to is it really worth it assuming we can gzip/brotili?
  • by wyldfire on 4/5/17, 1:12 PM

    If folks tend to use some higher level abstraction (isn't that what SASS and LESS are?) maybe it makes sense to provide a new way to encode the information in CSS. Similar to how WASM is supposed to be easier to parse than JavaScript, right?
  • by buster on 4/5/17, 10:13 AM

    I liked the writing style, fun read AND very informative!
  • by WhitneyLand on 4/5/17, 12:19 PM

    Are there any good tools for deobfuscating css/js if you want to study a technique used on some web page?
  • by bgrohman on 4/5/17, 7:13 PM

    I like your site design. Very clean and readable.
  • by cperciva on 4/5/17, 7:20 AM

    I'm for hire now. Le Sigh. Email's in the footer.

    Remy: I'd suggest posting a CV and linking to it from this post. I looked and couldn't find one anywhere on your site; you'll get a lot more qualified interest if people can find out more about you than just a few blog posts.