Because many projects use JavaScript, JavaScript is compressed to improve system efficiency.
To successfully compress multiple JavaScript files, you must go through the following two steps.
1. Merge multiple JavaScript codes into one js.
2. Compress and the following JavaScript code.
Ant configurations used mainly include:
<Property name = "root" value = "WebRoot"> </property>
<Property name = "js" value = "$ {root}/js"> </property>
<Property name = "map_function_js" value = "$ {js}/mapfunc"> </property>
<Property name = "lib" value = "lib"/>
<Property name = "build" value = "build"> </property>
<Property name = "war" value = "war"> </property>
<Property name = "war.info" value = "$ {war}/WEB-INF"> </property>
<Property name = "war. lib" value = "$ {war.info}/lib"> </property>
<Property name = "war. classes" value = "$ {war.info}/classes"> </property>
<Property name = "project. name" value = "zjmap"> </property>
<Property name = "charset" value = "UTF-8"/>
<Property name = "src" value = "src"/>
<Target name = "create build directory">
<Mkdir dir = "$ {build}"/>
</Target>
<! -- Merge multiple JavaScript codes into one js -->
<Target name = "merge js" depends = "create build directory">
<Concat destfile = "$ {build}/mapfuncall. js" encoding = "$ {charset}" outputencoding = "$ {charset}">
<Path = "$ {map_function_js}/DC. js"/>
<Path = "$ {map_function_js}/stringUtil. js"/>
<Path = "$ {map_function_js}/LOCALDC. js"/>
<Path = "$ {map_function_js}/screen. js"/>
<Path = "$ {map_function_js}/wfsQuery. js"/>
<Path = "$ {map_function_js}/Map. js"/>
<Path = "$ {map_function_js}/Query. js"/>
<Path = "$ {map_function_js}/ClassificationQuery. js"/>
<Path = "$ {map_function_js}/BusQuery. js"/>
<Path = "$ {map_function_js}/RouteQuery. js"/>
<Path = "$ {map_function_js}/cursorPosition. js"/>
<Path = "$ {map_function_js}/bufferAnalysis. js"/>
<Path = "$ {map_function_js}/divCtrl. js"/>
<Path = "$ {map_function_js}/mark. js"/>
<Path = "$ {map_function_js}/overlayAnalysis. js"/>
<Path = "$ {map_function_js}/BuildQuery. js"/>
<Path = "$ {map_function_js}/PopShow. js"/>
<Path = "$ {map_function_js}/correct. js"/>
<Path = "$ {map_function_js}/style_result.js"/>
<Path = "$ {map_function_js}/style_ui.js"/>
<Path = "$ {map_function_js}/Catalog. js"/>
<Path = "$ {map_function_js}/scenario. js"/>
<Path = "$ {map_function_js}/wfs. js"/>
<Path = "$ {map_function_js}/Uuid. js"/>
<Path = "$ {map_function_js}/Gps. js"/>
<Path = "$ {map_function_js}/typhoon. js"/>
<Path = "$ {map_function_js}/Monitor. js"/>
<Path = "$ {map_function_js}/RainWater. js"/>
<Path = "$ {map_function_js}/Approval. js"/>
<Path = "$ {map_function_js}/statistics. js"/>
<Path = "$ {map_function_js}/statisticsNew. js"/>
<Path = "$ {map_function_js}/OTileCacheCustom. js"/>
<Path = "$ {map_function_js}/BQTool. js"/>
<Path = "$ {map_function_js}/CityPositionQuery. js"/>
<Path = "$ {map_function_js}/IFieldService. js"/>
<Path = "$ {map_function_js}/SpecialQuery. js"/>
</Concat>
<Replaceregexp match = "@ debug @" replace = "" Flags = "G" byline = "true" file = "$ {build}/mapfuncall. JS "encoding =" $ {charset} "/>
</Target>
<! -- Use Yahoo UI for JS Compression -->
<Target name = "Start compression" depends = "merge JS">
<! -- Use Yahoo UI to compress mapfuncall. JS -->
<Antcall target = "compressing mapfuncall. js"> </antcall>
<! -- Use Yahoo UI to compress dataedit. JS -->
<Antcall target = "compressing dataedit. js"> </antcall>
<! -- Use Yahoo UI to compress Isuggest. JS -->
<Antcall target = "compressing Isuggest. js"> </antcall>
<! -- Copy the compressed JS file -->
<Antcall target = "copying and compressing JS Files"> </antcall>
</Target>
<Target name = "compressing mapfuncall. js">
<Java jar = "$ {lib}/Yui/yuicompressor-2.4.6.jar" fork = "true">
<Arg line = "-- Type JS -- charset UTF-8 $ {map_function_js}/mapfuncall. js-o $ {build}/mapfuncall-min.js"/>
</Java>
</Target>
<Target name = "compressing dataedit. js">
<Java jar = "$ {lib}/yui/yuicompressor-2.4.6.jar" fork = "true">
<Arg line = "-- type js -- charset UTF-8 $ {map_function_js}/dataedit. js-o $ {build}/dataedit-min.js"/>
</Java>
</Target>
<Target name = "compressing ISuggest. js">
<Java jar = "$ {lib}/yui/yuicompressor-2.4.6.jar" fork = "true">
<Arg line = "-- type js -- charset UTF-8 $ {map_function_js}/ISuggest. js-o $ {build}/ISuggest-min.js"/>
</Java>
</Target>
<Target name = "Clear build directory" depends = "Start compression">
<Delete dir = "$ {build}"/>
</Target>
<Target name = "copying and compressing js Files">
<Copy todir = "$ {map_function_js}">
<Fileset dir = "$ {build}">
<Include name = "**. js"/>
</Fileset>
</Copy>
</Target>
Reprinted please indicate the source: http://www.cnblogs.com/likehua