欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ANT 壓縮(去掉空格/注釋)JS文件可提高js運(yùn)行速度

 更新時(shí)間:2013年04月15日 11:50:14   作者:  
在解決這個(gè)有很多優(yōu)化方法,今天來(lái)說(shuō)其中一種,那就是在Ant腳本打包的時(shí)候,把js中空格、注釋去掉、以及合并,合并今天不說(shuō)了,還未實(shí)現(xiàn)這個(gè),在研究中
1、說(shuō)明在使用extjs 的時(shí)候,運(yùn)行起來(lái)比較卡,特別是運(yùn)行數(shù)據(jù)和js過(guò)多的時(shí)候,就會(huì)出現(xiàn)卡死的情況,或者等待時(shí)間比較長(zhǎng)。
在解決這個(gè)有很多優(yōu)化方法,今天來(lái)說(shuō)其中一種,那就是在Ant腳本打包的時(shí)候,把js中空格、注釋去掉、以及合并,合并今天不說(shuō)了,還未實(shí)現(xiàn)這個(gè),在研究中
2、首先,需要準(zhǔn)備二個(gè) .jar 文件,分別是 YUIAnt.jar 和 yuicompressor-2.4.x.jar 。
3、倆個(gè)文件的附件
下載地址
4、build.xml文件如下
復(fù)制代碼 代碼如下:

<!-- JS壓縮過(guò)程中的臨時(shí)目錄 -->
<property name="jsDir" value="${basedir}/release/web/js" />
<!-- CSS壓縮過(guò)程中的臨時(shí)目錄 -->
<property name="cssDir" value="${basedir}/release/web/css" />
<!-- ext3 css壓縮過(guò)程中的臨時(shí)目錄 -->
<property name="cssExtDir" value="${basedir}/release/web/ext3" />
<!-- ext3 js壓縮過(guò)程中的臨時(shí)目錄 -->
<property name="extUxJsDir" value="${basedir}/release/web/ext3/ux" />
<!-- JS源文件 -->
<property name="jsSourceDir" value="${webapp}/js" />
<!-- CSS源文件 -->
<property name="cssSourceDir" value="${webapp}/css" />
<!-- Ext CSS源文件 -->
<property name="cssExtSourceDir" value="${webapp}/ext3" />
<!-- Ext JS源文件 -->
<property name="extUxJsSourceDir" value="${webapp}/ext3/ux" />
<!-- yui 依賴包 -->
<path id="yuiClasspath">
<fileset dir="${basedir}">
<include name="metadata/tools/yui/yuicompressor-2.4.2.jar" />
<include name="metadata/tools/yui/YUIAnt-zh_CN.jar" />
</fileset>
</path>

復(fù)制代碼 代碼如下:

<!-- 開(kāi)始?jí)嚎sJS -->
<target name="copy-web-depress-js" depends="init">
<delete dir="${basedir}/release/web" />
<copy todir="${basedir}/release/web">
<fileset dir="${webapp}"/>
</copy>
<taskdef name="uxJsCompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<path refid="yuiClasspath" />
</classpath>
</taskdef>
<uxJsCompress linebreak="9000000" warn="false" charset="utf-8" encoding="utf-8" munge="yes" preserveallsemicolons="true" outputfolder="${extUxJsDir}">
<fileset dir="${extUxJsSourceDir}">
<include name="**/*.js" />
</fileset>
</uxJsCompress>
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<path refid="yuiClasspath" />
</classpath>
</taskdef>
<yuicompress linebreak="9000000" warn="false" charset="utf-8" encoding="utf-8" munge="yes" preserveallsemicolons="true" outputfolder="${jsDir}">
<fileset dir="${jsSourceDir}">
<include name="**/*.js" />
</fileset>
</yuicompress>
<taskdef name="cssYuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<path refid="yuiClasspath" />
</classpath>
</taskdef>
<cssYuicompress linebreak="9000000" warn="false" charset="utf-8" encoding="utf-8" munge="yes" preserveallsemicolons="true" outputfolder="${cssDir}">
<fileset dir="${cssSourceDir}">
<include name="**/*.css" />
</fileset>
</cssYuicompress>
<taskdef name="cssExtYuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<path refid="yuiClasspath" />
</classpath>
</taskdef>
<cssExtYuicompress linebreak="9000000" warn="false" charset="utf-8" encoding="utf-8" munge="yes" preserveallsemicolons="true" outputfolder="${cssExtDir}">
<fileset dir="${cssExtSourceDir}">
<include name="**/*.css" />
</fileset>
</cssExtYuicompress>
</target>
<!-- 結(jié)束壓縮JS -->

5、在這里說(shuō)一點(diǎn),在使用js壓縮的時(shí)候YUIAnt.jar 是不支持utf-8字符集的。即
復(fù)制代碼 代碼如下:

encoding="utf-8

下載地址
7、個(gè)人感受,在弄了很小半天,吧這個(gè)問(wèn)題搞定了,自以為可以提高點(diǎn)js加載速度了,結(jié)果還是有點(diǎn)小慢,沒(méi)有jquery那么的快,估計(jì)要用gzjs壓縮才會(huì)變快點(diǎn),現(xiàn)在我分析是的在IE下運(yùn)行速度比較慢點(diǎn),在firefox下比較快,看來(lái)還是每個(gè)模塊加載的js有點(diǎn)多。
優(yōu)化速度對(duì)比:

相關(guān)文章

最新評(píng)論