20 November 2009 3:08p Pacific

Using the Microsoft Ajax Minifier, some gotcha’s

by Matt Sherman

I am playing with the Microsoft Ajax Minifier, which removes whitespace from your Javascripts for quicker download. Stephen Walther has a nice how-to.

In my case, I am using the MSBuild task, which will minimize your Javascripts on build. Works great on my machine. But here’s the gotcha: if you have a build server that does not have the Minifier installed, your build will fail.

What to do? In my case, I updated Stephen’s MSBuild code with a Condition such that the task will only run under the Debug configuration. Thus, if your build server uses the Release configuration (as it should), the task will be ignored and your build won’t fail.

Here’s Stephen’s original code:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
 
<Target Name="AfterBuild">
 
<ItemGroup>
 
<JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
 
</ItemGroup>
 
<AjaxMin SourceFiles="@(JS)" SourceExtensionPattern="\.js$" TargetExtension=".min.js" />
 
</Target>


And here are my adjustments, note the Condition attributes:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" 
Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " /> <Target Name="AfterBuild"
Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <ItemGroup> <JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" /> </ItemGroup> <AjaxMin SourceFiles="@(JS)" SourceExtensionPattern="\.js$" TargetExtension=".min.js" /> </Target>


Hope this helps!

Comments are closed

Tell others

TwitterTweet this page
Digg!Digg this page
TwitterAdd to Google Reader

Experimental! Let me know how it works for you.

Shorten this page's URL

Learn more about the TinyASP URL shortener

ASP.Net jQuery Controls

Implement jQuery effects using familiar ASP.Net server controls. Learn more...

Recent posts

Avoiding “magic strings” in jQuery, C# and ASP.net MVC

Alikewise learnings #1: DIY PR

Sherman’s law of prior knowledge, or, predicting the past

The busiest people at Apple right now…

When “infographics” jump the shark

HTTPS is the least of your problems

Stacking up

Beware the truth-tellers

more...  

About us

ClipperHouse.com is brought to you by Matt Sherman and Fernando Chilvarguer, among others. Contact us here.