ANT 壓縮(去掉空格/注釋)JS文件可提高js運(yùn)行速度
更新時(shí)間:2013年04月15日 11:50:14 作者:
在解決這個(gè)有很多優(yōu)化方法,今天來說其中一種,那就是在Ant腳本打包的時(shí)候,把js中空格、注釋去掉、以及合并,合并今天不說了,還未實(shí)現(xiàn)這個(gè),在研究中
1、說明在使用extjs 的時(shí)候,運(yùn)行起來比較卡,特別是運(yùn)行數(shù)據(jù)和js過多的時(shí)候,就會(huì)出現(xiàn)卡死的情況,或者等待時(shí)間比較長(zhǎng)。
在解決這個(gè)有很多優(yōu)化方法,今天來說其中一種,那就是在Ant腳本打包的時(shí)候,把js中空格、注釋去掉、以及合并,合并今天不說了,還未實(shí)現(xiàn)這個(gè),在研究中
2、首先,需要準(zhǔn)備二個(gè) .jar 文件,分別是 YUIAnt.jar 和 yuicompressor-2.4.x.jar 。
3、倆個(gè)文件的附件
下載地址
4、build.xml文件如下
<!-- JS壓縮過程中的臨時(shí)目錄 -->
<property name="jsDir" value="${basedir}/release/web/js" />
<!-- CSS壓縮過程中的臨時(shí)目錄 -->
<property name="cssDir" value="${basedir}/release/web/css" />
<!-- ext3 css壓縮過程中的臨時(shí)目錄 -->
<property name="cssExtDir" value="${basedir}/release/web/ext3" />
<!-- ext3 js壓縮過程中的臨時(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>
<!-- 開始?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、在這里說一點(diǎn),在使用js壓縮的時(shí)候YUIAnt.jar 是不支持utf-8字符集的。即
encoding="utf-8
下載地址
7、個(gè)人感受,在弄了很小半天,吧這個(gè)問題搞定了,自以為可以提高點(diǎn)js加載速度了,結(jié)果還是有點(diǎn)小慢,沒有jquery那么的快,估計(jì)要用gzjs壓縮才會(huì)變快點(diǎn),現(xiàn)在我分析是的在IE下運(yùn)行速度比較慢點(diǎn),在firefox下比較快,看來還是每個(gè)模塊加載的js有點(diǎn)多。
優(yōu)化速度對(duì)比:
在解決這個(gè)有很多優(yōu)化方法,今天來說其中一種,那就是在Ant腳本打包的時(shí)候,把js中空格、注釋去掉、以及合并,合并今天不說了,還未實(shí)現(xiàn)這個(gè),在研究中
2、首先,需要準(zhǔn)備二個(gè) .jar 文件,分別是 YUIAnt.jar 和 yuicompressor-2.4.x.jar 。
3、倆個(gè)文件的附件
下載地址
4、build.xml文件如下
復(fù)制代碼 代碼如下:
<!-- JS壓縮過程中的臨時(shí)目錄 -->
<property name="jsDir" value="${basedir}/release/web/js" />
<!-- CSS壓縮過程中的臨時(shí)目錄 -->
<property name="cssDir" value="${basedir}/release/web/css" />
<!-- ext3 css壓縮過程中的臨時(shí)目錄 -->
<property name="cssExtDir" value="${basedir}/release/web/ext3" />
<!-- ext3 js壓縮過程中的臨時(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ù)制代碼 代碼如下:
<!-- 開始?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、在這里說一點(diǎn),在使用js壓縮的時(shí)候YUIAnt.jar 是不支持utf-8字符集的。即
復(fù)制代碼 代碼如下:
encoding="utf-8
下載地址
7、個(gè)人感受,在弄了很小半天,吧這個(gè)問題搞定了,自以為可以提高點(diǎn)js加載速度了,結(jié)果還是有點(diǎn)小慢,沒有jquery那么的快,估計(jì)要用gzjs壓縮才會(huì)變快點(diǎn),現(xiàn)在我分析是的在IE下運(yùn)行速度比較慢點(diǎn),在firefox下比較快,看來還是每個(gè)模塊加載的js有點(diǎn)多。
優(yōu)化速度對(duì)比:
相關(guān)文章
ExtJs 3.1 XmlTreeLoader Example Error
ExtJs 3.1的XmlTreeLoader例子折騰了我近一個(gè)下午加晚上,官方的例子沒有問題,可以加載xml的數(shù)據(jù),本地IIS死活不行2010-02-02
關(guān)于extjs4如何獲取grid修改后的數(shù)據(jù)的問題
如何獲取grid修改后的數(shù)據(jù)問題,下面是API的描述。可以獲取各種值,感興趣的朋友可以參考下2013-08-08
ExtJS4如何自動(dòng)生成控制grid的列顯示、隱藏的checkbox
需要做一個(gè)控制grid列顯示的checkboxgroup,雖然EXTJS4中的gridpanel自帶列表可以來控制列的顯示隱藏,需要的朋友可以參考下2014-05-05
Ext JS框架中日期函數(shù)的用法及日期選擇控件的實(shí)現(xiàn)
Ext JS中的Ext.Date可以看作是JavaScript中date的加強(qiáng)版,提供了許多進(jìn)階的日期操作函數(shù),下面我們就來看一下Ext JS框架中日期函數(shù)的用法及日期選擇控件的實(shí)現(xiàn)2016-05-05
Extjs學(xué)習(xí)筆記之八 繼承和事件基礎(chǔ)
只有有了事件,頁面才能真正的“活”起來。Extjs的事件也是經(jīng)過良好封裝的,對(duì)于事件的處理都由Ext.uitl.Observable類提供接口。2010-01-01
ExtJS[Desktop]實(shí)現(xiàn)圖標(biāo)換行示例代碼
ExtJS中的desktop的demo中,默認(rèn)的圖標(biāo)排列是不換行的,以下代碼就是為了解決這一問題的,需要的朋友可以了解下2013-11-11
ExtJs 學(xué)習(xí)筆記 Hello World!
最近學(xué)ajax,接觸到了Extjs這個(gè)強(qiáng)大的框架。我想通過我的學(xué)習(xí)筆記,最后可以讓大家上手在項(xiàng)目中使用Ext。首先我會(huì)寫一些基本的用于入門Ext的文章,打好基礎(chǔ)是很重要的。2008-12-12
extjs 學(xué)習(xí)筆記(一) 一些基礎(chǔ)知識(shí)
相信很多人對(duì)使用js進(jìn)行客戶端的編程比較頭大,其實(shí)現(xiàn)在已經(jīng)有了很多優(yōu)秀的js庫,可以大大簡(jiǎn)化js編程的工作量,其中,jquery和extjs就是兩款非常優(yōu)秀的js庫。2009-10-10
extjs關(guān)于treePanel+chekBox全部選中以及清空選中問題探討
treePanel+chekBox全部選中以及清空選中,想必大家在學(xué)習(xí)使用過程中都見過這種效果吧,接下來為大家詳細(xì)介紹下實(shí)現(xiàn)過程及細(xì)節(jié),感興趣的朋友可以參考下哈2013-04-04

