Any recommendations for a CSS minifier? [closed]

2019-01-01 08:02发布

问题:

Any recommendations for a CSS minifier?

I’ll be rooting around Google and trying some out, but I suspected that the smart, proficient and curiously handsome StackOverflow community might have already evaluated the pros and cons of the heavyweights.

回答1:

The YUI Compressor is fantastic. It works on JavaScript and CSS. Check it out.



回答2:

There\'s also a .NET port of YUI Compressor which allows you to:-

  • intergrate the minification/file combining into Visual Studio post-build events
  • intergrate into a TFS Build (including CI)
  • if you wish to just use the dll\'s in your own code (eg. on the fly minification).

UPDATE 2011: And it\'s now available via NuGet also :)



回答3:

I like Minify. In PHP and works with CSS or JavaScript.



回答4:

CSSO is currently best minifier/optimizer.



回答5:

If you use Python I would recommend slimmer which is probably not as fast as YUI Compressor but unlike csscompressor.net it doesn\'t choke on CSS hacks.

I\'m biased since I wrote slimmer and I\'m currently evaluating YUI Compressor to see how it handles hacks. An example of slimmer in action can be seen if you view the source of crosstips.org



回答6:

Check out CSSTidy: http://csstidy.sourceforge.net/usage.php

And online at: http://cdburnerxp.se/cssparse/css_optimiser.php



回答7:

If you are looking for an online tool, try this: https://csscompressor.net/



回答8:

I\'ve written an ultra fast CSS minifier in C#. The algorithm does not handle Javascript though. Thy this: http://www.ko-sw.com/Blog/post/An-Ultra-Fast-CSS-Minify-Algorithm.aspx.



回答9:

Try closure-stylesheets.

Beside minification it also supports linting, RTL flipping, and class renaming.

It can also add variables, functions, conditionals, and mixins to CSS.

Also note that some of these features depend on rest of Closure Tools (which are very powerful on their own).



回答10:

If you\'re looking for something in PHP, here\'s the link:-

Fat-Free Minify

Although it\'s part of the PHP Fat-Free Framework, it can also be used stand-alone.



回答11:

I find that isnoop\'s CSS SuperScrub works very well. It can only handle direct links to CSS online though :/ You can get around that though by using your preferred pastebin service to hold the css code and just giving SuperScrub the raw link.



回答12:

If your site is in ASP.NET, you can let your site do the CSS minification on the fly (so you don\'t have to do it manually each time you make a change). For example with this:

http://www.codeproject.com/KB/aspnet/CombineAndMinify.aspx



回答13:

Perl has CSS::Minifier (and an XS version for extra speed).



回答14:

Others have mentioned YUI Compressor, then the .NET port of it, and I\'ll add another link to the chain. StyleManager is a server control which wraps up the .NET port of YUI Compressor so you can use it just like you\'re used to using ScriptManager. It adds a bunch of other nice features too, like CSS constants, tilde (~) resolution w/in your background-image definitions, etc etc. It\'s tight, well documented, and I\'ve used it on all my recent projects w/o an issue. Check it out - gStyleManager.com



回答15:

Still \"in beta\", but should work fairly well. I use the code behind it in every project: http://claudiu.phpfogapp.com/ It\'s built in PHP and also hosts your *.css file for a fairly large amount of time, surely enough to let you test your code with the minified css. (I would only delete old css files if the space gets crowded on the server).



回答16:

There is a codeplex project that will plug in to .net websites that will minify and compress the CSS and the JS files. There is also a comparison between the Microsoft AJAX Minifier and the YUI Compressor which shows the YUI coming out slightly better. There is an extra variation which combines the Microsoft Minifier and compression which drastically srunk the file.

Anyway the link is http://xpedite.codeplex.com/wikipage?title=Minifier%20(CSS%2FJavaScript%20Minification%20Handlers)



回答17:

This is how I did it for MVC3: http://mkramar.blogspot.com/2011/08/css-and-javascript-minify-and-combine.html The beauty of this approach is that it does it all on the fly and you don\'t have to pre-process files manually or configure post-build.



回答18:

An online tool (much better than www.csscompressor.net which jacked my css up): http://www.cssdrive.com/compressor/compress.php does an excellent job.



回答19:

C# example:

css = css.Replace(\"\\n\", \"\");
css = Regex.Replace(css, @\"\\s+\", \" \");
css = Regex.Replace(css, @\"\\s*:\\s*\", \":\");
css = Regex.Replace(css, @\"\\s*\\,\\s*\", \",\");
css = Regex.Replace(css, @\"\\s*\\{\\s*\", \"{\");
css = Regex.Replace(css, @\"\\s*\\}\\s*\", \"}\");
css = Regex.Replace(css, @\"\\s*\\;\\s*\", \";\");


回答20:

zbugs.com will be a good online tool for you, it will minify your css in a single click



回答21:

Have a peek at the latest HTML5BoilerPlate by Paul Irish - it contains a build script to minify all your assets (including PNG\'s and JPG\'s). You can see a demo video here.



标签: css minify