Is there an advanced CSS minifier/compiler that does things like strip redundancy and comma separate identical rules?

后端 未结 11 1779
暗喜
暗喜 2020-12-09 03:22

For example

input{margin:0}body{margin:0;background:white}

would be shorter written like this

input,body{margin:0}body{back         


        
11条回答
  •  独厮守ぢ
    2020-12-09 03:56

    No, there is no such tool which optimizes to the level you ask (that I'm aware of at least), and I'm not sure you'd want to use it if there was. The reason is that it's not a trivial problem to find the smallest possible minified css code. For the trivial CSS you provided, it's easy. But imagine doing that on a 300kb block of CSS. It's not trivial. And is it worth wasting the CPU time generating it (it might be if you're caching the results, but it won't be if you're serving it dynamically)?

    And what's the gain? Saving a few percent at most on the transfer? Unless you have facebook level traffic, you're not going to save much bandwidth. And a few percent isn't going to impact your users much either (even over dial-up, transferring a few kb isn't that bad).

    Just use a standard compressor (minify, YUI Compressor, etc) and be done with it. Instead, worry about the low hanging fruit. The easy to fix problems...

提交回复
热议问题