187 people following this project (follow)

NOTICE : Work has begun on a version 2.0 release - this means that the latest code is NOT the same as the NuGet package or the manual downloaded zips. Version 1.7.0.1 was the latest code release to represent the NuGet package/Zip Downloads.


Project Description
This is a .NET port of the Yahoo! UI Library's YUI Compressor Java project. The objective of this project is to compress any Javascript and Cascading Style Sheets to an efficient level that works exactly as the original source, before it was minified.

Available via NuGet
NuGet Command

NuGet Command with MSBuild Task

NOTE: I've now removed the .NET3.5 and .NET2.0 binaries from the Codeplex Download tab/page -- Please use NuGet from now on (or download the source code and compile em yourself, if you need the .NET2.0 binaries because they are not/will not go up onto NuGet).


Main Features
  • Stock YUI Css compression.
  • Stock YUI JavaScript compression.
  • Visual Studio post-build event intergration! :) (with detailed instructions here and the download section has a sample solution showing this)
  • MsBuild task which can be used in a Web Deployment Project build. (The download section has a sample solution showing this)
  • The MsBuild task also compiles all compressed files into a single destination file (aka. file combining).
  • Can now handle Encoding Types (eg. Unicode) from v1.2.2.0 onwards and ThreadCulture from v1.3.0.0 onwards.
  • Can handle wildcards (eg. *.js), because it uses MSBuild as the core engine :)

Referenced Version
Based on YUI Compressor version: 2.4.4 (last checked at 2011-01-17).

How close to the Java Port?
Pretty damn close, now :) Same unit tests (which pass).
The only thing I haven't been able to do is get the exact same obfuscation because the java code is using a hashtable instead of a sorted hashtable/dictionary. It's identical besides that (and works the same). Just visually look different but is exactly the same file size, etc.

Who's utilising this code/library?
If you use this code in some project, please drop us a message so we can include it in this list :)
Sample Code : Css Compression

using Yahoo.Yui.Compressor;

...

string compressedCss;

// Note: string css == some cascading style sheet data loaded from some file, etc.
compressedCss = CssCompressor.Compress(css);  // No column width's specified.
compressedCss = CssCompressor.Compress(css, 73); // Column width of 73 specified,for nice reading 
                                                 //     if that's what you want.


Sample Code : JavaScript Compression

using Yahoo.Yui.Compressor;

...

string compressedJavaScript;

// Note: string javaScript == some javascript data loaded from some file, etc.
compressedJavaScript= JavaScriptCompressor.Compress(javaScript);  

Sample MsBuild output




Sample MSBuild.xml file, which Visual Studio Post-build Events or Web Deployment Projects use
Read all about it here.

YouTube Video Tutorials
Using YUI Compressor .NET with VS2008 + Post Build Events

Using YUI Compressor .NET with MSBuild

References
YUI Compressor home page: http://developer.yahoo.com/yui/compressor/
DimeBrain's YUI Css Compressor port: http://www.dimebrain.com/2008/03/a-better-css-mi.html
Michael Ash's Regex Compression: http://regexadvice.com/blogs/mash/archive/2008/04/27/Update-to-CSS-Minification.aspx

Last edited Apr 10 at 1:40 AM by purekrome, version 52