Minifying & bundling CSS/Javascript in .NET

It all started a while ago with a little speed test on my dating site Vibbar when I was refactoring some code there. In the heat of the moment (long nights pre-release) I hadn’t minified nor bundled any of the CSS/javascript we are using there, resulting in a heap of requests and lots of extra kilobytes being transferred for nothing. I started to think in the lines of writing a own class for .NET which I could use in my other projects to do exactly what I get for free when coding in Ruby on Rails, an “on-the-fly” minifier/bundler (let’s face it, I am to sloppy to remember to do it manually before every deploy).

After a quick little search I found out that there already is a great library which uses YUI Compressor and in fact works the exact way I want it to (with specific bundling and the ability to turn it off during development mode). SquishIt to the rescue! It’s open-source (yummy) and you can find the source along with downloads at Github, there is also a little guide by the creator of SquishIt here. It works great with CSS/JS and according to some sources even works with LESS.

If you don’t wan’t the source you can easily install SquishIt with NuGet

Install-Package SquishIt

A little example: