Packer for .NET
Recognition
It was great to see that Scott Hanselman has placed Packer for .NET on his annual list.
Included Packages
What is it?
Packer for .NET is a tool derived from Packer which reduces the size of JavaScript files. The changes made with Packer for .NET include a command-line version which uses the same classes included with the official Packer download. This command-line tool can take multiple filenames to compress them all together into a single packed output. The existing WinForms version limited the amount of text allowed in the input window and did not take filenames as input. This re-packaged version makes it easier to automate build and deployment tasks.
Packer for .NET also supports a mode to use JSMin. It uses a different process which simply strips comments and whitespace from the source scripts. In the cases where the Packer mode is unable to transform a script it may be possible to use JSMin instead.
Packer versus JSMin?
The merits of Packer and JSMin can be measured in file size and time to interpret. While Packer can created a much smaller output file it can be more problematic with packing JavaScript that does not conform to a strict syntax. JSMin still prefers that you use semicolons at the end of each line, but it tends to have fewer problems with parsing and minifying the output. Beyond file size, the time it takes interpret a packed/minified JavaScript file should also be a consideration. Resig ran a series of tests with Packer and JSMin and determined that JSMin appears to give you the best of compression and time for interpretation while Packer does have a performance hit when it has to be unpacked and interpreted.
One tool to assist with ensuring JavaScript works well with Packer and JSMin is JavaScript Lint which integrates well with Visual Studio. See the links below.
Command-line Usage
Usage: Packer [-?|-h] [-o <filename>] [-m <packer | jsmin>] <script1> <script2> ... Options: -h or -? Help -o <filename> Output Filename -m <packer | jsmin> Mode
MSBuild Usage
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\SmallSharpTools.Packer\MSBuild.Packer.Targets" />
<PropertyGroup>
<PackerOutputFileName>packer.msbuild.js</PackerOutputFileName>
<JSMinOutputFileName>jsmin.msbuild.js</JSMinOutputFileName>
</PropertyGroup>
<ItemGroup>
<InputFiles Include="scripts\*.js" />
</ItemGroup>
<Target Name="Build">
<Packer OutputFileName="$(PackerOutputFileName)" Mode="Packer" InputFiles="@(InputFiles)" Verbose="false" />
<Packer OutputFileName="$(JSMinOutputFileName)" Mode="JSMin" InputFiles="@(InputFiles)" Verbose="false" />
</Target>
</Project>
More Information
Credits
Packer was originally ported to C# by Jessie Hansen. (See Packer Goes .NET)
JSMin was created by Douglas Crockford. (www.crockford.com)
