Use ANT and YUI compression js implementation method

  • 2020-04-01 01:59:10
  • OfStack

Because the project USES a lot of js, in order to improve the efficiency of the system, js compression processing.
To successfully compress multiple js, you must go through the following two steps.
1. Merge multiple js into one js.
2. After and and and js compression processing.
The main ant configurations used are:

<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>


 <!--  multiple js Merge into one js -->
  <target name=" merge js" depends=" create build directory ">
          <concat destfile="${build}/mapfuncall.js" encoding="${charset}" outputencoding="${charset}">
           <path path="${map_function_js}/DC.js" />
        <path path="${map_function_js}/stringUtil.js" />
           <path path="${map_function_js}/LOCALDC.js" />
           <path path="${map_function_js}/screen.js" />
           <path path="${map_function_js}/wfsQuery.js" />
           <path path="${map_function_js}/Map.js" />
           <path path="${map_function_js}/Query.js" /> 
           <path path="${map_function_js}/ClassificationQuery.js" /> 
           <path path="${map_function_js}/BusQuery.js" /> 
           <path path="${map_function_js}/RouteQuery.js" />
           <path path="${map_function_js}/cursorPosition.js" />
           <path path="${map_function_js}/bufferAnalysis.js" />
           <path path="${map_function_js}/divCtrl.js" />
            <path path="${map_function_js}/mark.js" />
           <path path="${map_function_js}/overlayAnalysis.js" />
           <path path="${map_function_js}/BuildQuery.js" />
           <path path="${map_function_js}/PopShow.js" />
           <path path="${map_function_js}/correct.js" />
           <path path="${map_function_js}/style_result.js" />
            <path path="${map_function_js}/style_ui.js" />
           <path path="${map_function_js}/Catalog.js" />
           <path path="${map_function_js}/scenario.js" />
           <path path="${map_function_js}/wfs.js" />
           <path path="${map_function_js}/Uuid.js" />
           <path path="${map_function_js}/Gps.js" />
           <path path="${map_function_js}/typhoon.js" />
           <path path="${map_function_js}/Monitor.js" />
           <path path="${map_function_js}/RainWater.js" />
           <path path="${map_function_js}/Approval.js" />
           <path path="${map_function_js}/statistics.js" />
           <path path="${map_function_js}/statisticsNew.js" />
           <path path="${map_function_js}/OTileCacheCustom.js" />
           <path path="${map_function_js}/BQTool.js" />
           <path path="${map_function_js}/CityPositionQuery.js" />
           <path path="${map_function_js}/IFieldService.js" />
           <path 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 The compression  -->
 <target name=" To compress " depends=" merge js">
          <!--  Use yahoo! UI The compression  mapfuncall.js -->
         <antcall target=" The compression mapfuncall.js"></antcall>
           <!--  Use yahoo! UI The compression  dataedit.js -->
         <antcall target=" The compression dataedit.js"></antcall>
          <!--  Use yahoo! UI The compression  ISuggest.js -->
         <antcall target=" The compression ISuggest.js"></antcall>
         <!--  Copy the compressed js file  -->
         <antcall target=" Copy the compression js file "></antcall>
 </target>
 <target name=" The compression 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=" The compression 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=" The compression 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=" remove build directory " depends=" To compress ">
          <delete dir="${build}"/>
  </target>
 <target name=" Copy the compression js file ">
      <copy todir="${map_function_js}">
         <fileset dir="${build}">
                   <include name="**.js"/>
            </fileset>
      </copy>
 </target>

Related articles: