Efficient stylesheet minification in C#

Feb 28, 2010
A few weeks back i found out that the method I use to minify CSS was about 5% more efficient than the YUI Compressor. I tweeted about it and was encouraged to post the code that does the actual minification. public static string RemoveWhiteSpaceFromStylesheets(string body) {   body = Regex.Replace(body, @"[a-zA-Z]+#", "#");  body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty);  body = Regex.Replace(body, @"\s+", " ");  body = Regex.Replace(body, @"\s?([:,;{}])\... [More]* $4.95/month ASP.NET Hosting with FREE SQL 2012 DB! – Click Here!

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.