TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

CSS Reminification: A crazy idea that worked

230 pointsby remy_luisantabout 8 years ago

34 comments

bastawhizabout 8 years ago
Author of crass here.<p>I wouldn&#x27;t recommend doing what the author suggests. crass doesn&#x27;t squeak out extra bytes when you reprocess because it already does this for you.<p>If you combine multiple minifiers, the bugs in one minifier can end up being amplified by the others. For instance, one minifier might not consider !important when moving around CSS. Another minifier might then take that output and perform an optimization that&#x27;s no longer just unsafe, but now incorrect. It might even delete rulesets that it believes are not used, ruining your stylesheet.<p>There are suites that test the correctness of minifieres, and many don&#x27;t do great. CSS still &quot;works&quot; when the syntax is invalid, so invalid stylesheets result in undefined results when you minify. Between bugs and undefined behavior, I wouldn&#x27;t recommend mixing and matching just to save one or two TCP packets, especially with gzip&#x2F;brotli on the wire.
评论 #13826830 未加载
评论 #13829495 未加载
评论 #13829504 未加载
kzrdudeabout 8 years ago
Chaining was not exactly the level of innovation that the introduction set up for.
评论 #13826953 未加载
BuuQu9huabout 8 years ago
I worry that this is the chaos of folks not understanding compiler theory. This is the result: every minifier is a compiler, but none of these minifiers boast properties like idempotence and none of them are sufficiently correct that they achieve their goal on the first try. I don&#x27;t expect to necessarily see scholarly papers, but I would not ever expect a minifier to improve on itself when run multiple times in a row!
评论 #13826297 未加载
评论 #13826366 未加载
评论 #13829167 未加载
Exumaabout 8 years ago
Your site is very nicely styled and easy to read... I like how large and legible and clean-looking the font is.<p>Also, your writing style is funny, nice work.
评论 #13827286 未加载
sbierwagenabout 8 years ago
If you really want to get fancy you could use Selenium to get screenshots and compare them to check that the remynified CSS produces the same layout as the original CSS.<p><a href="http:&#x2F;&#x2F;www.seleniumhq.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.seleniumhq.org&#x2F;</a>
评论 #13826019 未加载
评论 #13825675 未加载
评论 #13828224 未加载
评论 #13828225 未加载
huulaabout 8 years ago
Transforming .a-really-long-class-name-or-id into something shorter, like .x would save a lot more bytes.<p>Another thing is splicing unecessary properties, which can even save more bytes, but given web apps becoming becoming so dynamic right now, that would be hard or really awkward for developer to work with too.
评论 #13825904 未加载
评论 #13825793 未加载
评论 #13826292 未加载
quakenulabout 8 years ago
I really can&#x27;t tell if this is satire. But either everyone is in on the joke and out to get naive people like me (in that case, well played) or Hacker News does not seem to think so.<p>I don&#x27;t think there is one single use case, on any scale, anywhere in the world, where saving up to 17% on a minimized css file before gzip would matter in the slightest, let alone while adding 20mins to your build cycle :)
评论 #13826867 未加载
评论 #13826327 未加载
bluetwoabout 8 years ago
I am not a fan of css minimizers.<p>I&#x27;m more a fan of writing compact, clean, logical css in the first place.<p>A couple months ago I worked on a project and re-wrote a 129k minified css file someone created as a clean un-minified 12k css file that had 100% of the original functionality plus some additional UI improvements.<p>You can only get these improvements if you understand what you are writing and stop using sass to write bloated files.
评论 #13827895 未加载
评论 #13828874 未加载
评论 #13828514 未加载
评论 #13829209 未加载
评论 #13829120 未加载
destructionatorabout 8 years ago
`rm bootstrap.css` look, a 100% reduction! And it led to a better website.<p>`gzip goodfile.css` and there&#x27;s an improvement several times more effective than even the best minifier. And it keeps your source code legible in the browser and doesn&#x27;t require a slow&#x2F;buggy asset pipeline to test changes.<p>Yes, yes, I know minify+gzip can save like an additional 1% over what gzip alone does. To me, that&#x27;s just not worth the cost to the developer.
评论 #13829604 未加载
评论 #13829388 未加载
评论 #13829503 未加载
rodrigocoelhoabout 8 years ago
What really reduces css filesize for me is uncss[0]. It removes the unused styles and then I run the css through a minifier to finish the job.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;giakki&#x2F;uncss" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;giakki&#x2F;uncss</a>
xiamxabout 8 years ago
Great work! There are several directions where you can make your work more substantial. For once it would be interesting to see what&#x27;s the marginal benefit of iterative minification over iterations (can be represented in a graph). Does Remynification approach an asymptotic size value, will further minification actually increase the size instead of decreasing? Also, it would be interesting to take screenshot using selenium as suggested by sbierwagen and see if Remynification actually preserves initial layout. Lastly, it would be interesting to see a theory proposed as why such method work, and what can future minifier learn from this.
Exumaabout 8 years ago
I would be extremely curious to find out what modifications were made by the minifiers in round 2 and onwards that it couldn&#x27;t have caught the first time...?<p>JS or HTML I suppose I could see, because they&#x27;re more complicated, but CSS by itself is very simple, so I&#x27;m wondering what actually got left out.<p>Do you have any diffs or info on what it was removing or doing?
评论 #13826849 未加载
plaguuuuuuabout 8 years ago
In practice this is going to be gzipped before being sent over the wire right? What&#x27;s the gzipped size difference?<p>Something something entropy
评论 #13826240 未加载
quinkabout 8 years ago
I found that rearranging by desired output seemed to work better, especially once you consider that compression works best on repeated longer strings. With minification as it stands you&#x27;re forced to have the longer strings once, with the short strings (the CSS properties) repeated a lot.<p>This is exactly backwards from what you want. You want the short strings to appear infrequently, and the longer strings a lot.<p>CSS resets sheets are a bad example for this kind of thing, as they&#x27;re strongly sorted by desired output property, but for general CSS for something with a lot of components, for example, or a CSS sheet with page template specific styling, it seems like it should minify and gzip a lot better.<p>Plus, you can group your CSS by relevant section, i.e. keep your colours separate from your alignment, from your fonts, etc.<p>Except the problem is that doing it this way requires a bit of rearranging of the rules, which may cause some trouble in a fairly small number of cases, so that&#x27;s why it&#x27;s out as an automated way of minifying things.
cjhanksabout 8 years ago
Does your &quot;reminified&quot; CSS actually compress better under GZIP than any of the independent minifiers? The variance you were seeing looks to be irrelevant in comparison.
评论 #13827326 未加载
Brockensteinabout 8 years ago
&quot;It took 25 extra minutes to save this 261 bytes. Worth it? You decide.&quot;<p>I think I&#x27;ve decided it&#x27;s obviously not worth it, even if we built a time machine and sent the css back to 1955 when they&#x27;d appreciate 261 bytes difference. (Granted they had no use for CSS in 1955).
dahartabout 8 years ago
I totally read the title as &quot;Remnification&quot; and &quot;Remnyfication&quot;. I didn&#x27;t see the right spelling until I got to section 5! &quot;OH! RE-minification&quot;... ;)<p>Very nice, this is a fun project and a nice write up. I would definitely worry about lossy minification on production code, I&#x27;ve bumped into many minifier bugs that broke my valid CSS.<p>Also, pretty sure you could get Bootstrap.css down to a couple k-bytes and really truly pwn the file size leaderboard if you could dead-strip all the rules not actually referenced in your HTML &amp; JS.
评论 #13827046 未加载
评论 #13828535 未加载
tpetryabout 8 years ago
The problem with such a tree optimization is that you will only find a locally best solution.<p>If compressor1 generates the smallest result in step 1 all other compressors will only try to minimize this result. But maybe the compressor did something which the other conpressors are not optimized for. So you&#x27;ll find a lically best solution for a starting point with conpressor1. But maybe it would have been better to start with compressor3 because it&#x27;s result is smaller after step 2 than starting with compressor1.
SZJXabout 8 years ago
This just makes no sense. If somehow the minimizer wasn&#x27;t able to further process it, maybe it&#x27;s just because it was already quite thoroughly processed and you will loss some information if you continue? That&#x27;s totally unsound approach. What does that extra fee bytes of saving do to loading time anyways? Probably very little, yet you risk very real degradation and broken behaviors.<p>Not to mention the author even admitted to not being very proficient in CSS and doesn&#x27;t even want to learn JS because he &quot;dislikes it too much&quot;... The whole description of the process is basically dragging something on out of very little substance.<p>In general good laughing material though, just as he acknowledged at the end of the article, I guess.
vmarsyabout 8 years ago
This is pretty cool!<p>&gt; Are the current CSS minifiers correct?<p>&gt; I handle crashing minifiers, as well as ones that loop forever.<p>It could actually be useful to know the exact css before running the minifier who crashed&#x2F;got stuck. One could check with a css validator if this is correct css in the first place (if not, one of the previous minifier screwed up) , and if so, inform the minifier&#x27;s maintainers of their tool crashing with this particular valid input.
评论 #13825878 未加载
dullroarabout 8 years ago
&quot;IT...COULD...WORK!!!&quot; - Dr. Frederick Frankenstein<p>Cool idea. Especially not reinventing wheels but chaining them together instead. Good work.
bgirardabout 8 years ago
This doesn&#x27;t explore where the additional savings are coming from so that they can be contributed back into minifiers.
评论 #13826878 未加载
znpyabout 8 years ago
I wonder what the impacts of (re|)minification is on actual network performance.<p>For example: consider a minified file x. X is likely getting gzipped when served. Is the reminified version smaller than the original? Same size? Bigger?<p>You might expect the obvious answer, but did anyone do the actual measurements?
评论 #13826852 未加载
martijndehabout 8 years ago
I&#x27;m curious though, how do these minifications, or CSS minifications in general, affect runtime performance? Reducing the file size is great, and a goal in itself (though brotli is more important where gzip is supported), but another important goal is rendering the page fast. Some CSS selectors are faster than others, is this something minifiers take into account? Or is this not significant at all?
评论 #13828226 未加载
sAbakumoffabout 8 years ago
&gt;&gt; There is a catch: Remynification takes forever and may break your CSS, even though this isn&#x27;t really my fault.<p>Stopped reading after this line.
评论 #13827228 未加载
SFJulieabout 8 years ago
Looking at modern websites: very few use the Accept-Encoding: gzip of the HTTP 1&#x2F;1<p>This could even «minify the served CSS» a lot :)<p>(ok client side it will always be as big, but the server side is often paying its traffic and the client side may too so it reduces traffic anyway and means great savings).<p>For public static websites, the savings induced by gzip compression totally justify to not use http2 when traffic matters.
评论 #13827597 未加载
tambourine_manabout 8 years ago
Good… (read in Palpatine&#x27;s voice)<p>Now rewrite all your selectors in optimum precedence and specificity for file size. After that, remember that it will all go through gzip, so let&#x27;s see how reordering properties affect compression.
barrystaesabout 8 years ago
Filesize is not necessarily better performance. On todays hardware i believe (but i have not tested this..) that opening a zipped 1MB file often is slower than just opening it directly, basically thats just shoving it in RAM.
评论 #13828480 未加载
Galanweabout 8 years ago
Minimizing the lossfull minifier from:<p><pre><code> #!&#x2F;bin&#x2F;bash rm -rf $1 touch $1 </code></pre> to<p><pre><code> #!&#x2F;bin&#x2F;sh &gt;&quot;$1&quot; </code></pre> Your turn, reddit
评论 #13828528 未加载
bikamonkiabout 8 years ago
I&#x27;m sorry, I have to:<p><a href="http:&#x2F;&#x2F;motherfuckingwebsite.com" rel="nofollow">http:&#x2F;&#x2F;motherfuckingwebsite.com</a>
d--babout 8 years ago
Remy, you forgot the y in remynification in the submission title. Cause it&#x27;s all about you after all! :)
snsrabout 8 years ago
&gt; <i>If lossy CSS minification is a thing that we are willing to put up with</i><p>I&#x27;m not, neat experiment though.
leni536about 8 years ago
And what&#x27;s the size difference comparing the gzipped css files?
ldevabout 8 years ago
Now I know why most of my colleagues in software development do not have a degree - academy really, really closes your mind in some strange bubble and shields you from real world...<p>This article - I don&#x27;t even...