最近做到了前端优化的一些工作,涉及到了自动化部署的问题。前端优化无非是雅虎的优化法则,不过如果想把优化法则加到自动化部署中去的话,下面的几种方法可以帮助你。
1、JS/CSS压缩脚本

	<!-- 压缩JS,CSS -->
	<target name="compress">
		<apply executable="java" parallel="false" failonerror="true">
			<fileset dir="${html-js}" includes="**/*.js" />
			<arg line="-jar" />
			<arg path="${yui-compressor}" />
			<arg line="--charset utf-8" />
			<srcfile />
			<arg line="-o" />
			<mapper type="glob" from="*.js" to="${webhtml-js}/*-min.js" />
			<targetfile />
		</apply>
		<apply executable="java" parallel="false" failonerror="true">
			<fileset dir="${html-css}" includes="**/*.css" />
			<arg line="-jar" />
			<arg path="${yui-compressor}" />
			<arg line="--charset utf-8" />
			<srcfile />
			<arg line="-o" />
			<mapper type="glob" from="*.css" to="${webhtml-css}/*-min.css" />
			<targetfile />
		</apply>
	</target>

2、更新JSS/CSS版本号

	<!-- 更新静态文件的版本号 -->
	<target name="version">
		<tstamp>
			<format property="TIMESTAMP" pattern="yyyyMMddHHmmss" locale="en" />
		</tstamp>
		<loadfile property="svn.version" srcFile="./.svn/entries">
			<filterchain>
				<headfilter lines="1" skip="3" />
				<deletecharacters chars="\n" />
			</filterchain>
		</loadfile>
		<delete file="${webinf-ftl}/config.ftl"/>
		<copy file="${ftl-app}/config.ftl" tofile="${webinf-ftl}/config.ftl" />
		<replace file="${webinf-ftl}/config.ftl" token="$version$" value="${svn.version}" />
	</target>

接下来就是合并JS/CSS文件

	<!-- 合并静态文件 -->
	<target name="js-concat">
		<concat destfile="${webhtml-js}/jquery.js" encoding="utf-8" append="false">
			<path path="${webhtml-js}/jquery.core-min.js" />
			<path path="${webhtml-js}/jquery.cookie-min.js" />
			<path path="${webhtml-js}/jquery.timeago-min.js" />
			<path path="${webhtml-js}/jquery.utils-min.js" />
			<path path="${webhtml-js}/jquery.watermarkinput-min.js" />
		</concat>
	</target>