亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

<!-- JS壓縮過程中的臨時目錄 -->
<property name="jsDir" value="${basedir}/release/web/js" />
<!-- CSS壓縮過程中的臨時目錄 -->
<property name="cssDir" value="${basedir}/release/web/css" />
<!-- ext3 css壓縮過程中的臨時目錄 -->
<property name="cssExtDir" value="${basedir}/release/web/ext3" />
<!-- ext3 js壓縮過程中的臨時目錄 -->
<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>

復制代碼 代碼如下:

<!-- 開始壓縮JS -->
<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、在這里說一點,在使用js壓縮的時候YUIAnt.jar 是不支持utf-8字符集的。即
復制代碼 代碼如下:

encoding="utf-8

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

相關(guān)文章

最新評論