Posted by & filed under AthleticHost, Web Development.

I have been working on creating a DotNetNuke Skin for AthleticHost.com.   In order to simplify deployment of the skin I wanted to add it as an extension to DNN rather that upload it via FTP.   I choose to use NAnt to build the extension install file.   In an effort to increase page performance I decided that the CSS and JavaScript files should be compressed and choose the YUI Compressor for the job.

I created two targets.  One to minify the JavaScript and another for the CSS.

<target name="JavaScript.minify">
<foreach item="File" property="filename">
  <in>
    <items>
      <include name="${temp.dir}/**/js/**/*.js"/>
    </items>
  </in>
  <do>
    <echo message="${filename}" />
    <exec program="java" workingdir="${YUICompressor.dir}">
      <arg value="-jar" />
      <arg value="yuicompressor-2.4.2.jar" />
      <arg value="--type" />
      <arg value="js" />
      <arg value="-o" />
      <arg value="${filename}.min" />
      <arg value="${filename}" />
    </exec>
    <move file="${filename}.min" tofile="${filename}" overwrite="true" />
  </do>
</foreach>
</target>
<target name="Css.minify">
<foreach item="File" property="filename">
  <in>
    <items>
      <include name="${temp.dir}/**/*.css"/>
    </items>
  </in>
  <do>
    <echo message="${filename}" />
    <exec program="java" workingdir="${YUICompressor.dir}">
      <arg value="-jar" />
      <arg value="yuicompressor-2.4.2.jar" />
      <arg value="--type" />
      <arg value="css" />
      <arg value="-o" />
      <arg value="${filename}.min" />
      <arg value="${filename}" />
    </exec>
    <move file="${filename}.min" tofile="${filename}" overwrite="true" />
  </do>
</foreach>
</target>

The “Deploy” target then calls the “Css.minify” and “Javascript.minify”

<call target="JavaScript.minify" />
<call target="Css.minify" />

Download the full NAnt script.

Resouces:
http://developer.yahoo.com/yui/compressor/
http://nant.sourceforge.net/

Trackbacks/Pingbacks

  1.  In the Wild for February 26, 2010 » Yahoo! User Interface Blog (YUIBlog)
  2.  In the Wild for February 26, 2010 ­ Share My Live

Leave a Reply

  • (will not be published)