今天研究了一下YUI yahoo开源框架,感觉很猛啊。

于是乎我做了一个YUI的ant实现,网上好多关于bat的实现,我就另辟蹊径,出个关于这个的ant实现,嘿嘿独一无二的文章,如果转载的话,其注明作者和网站

copyright:Mr.chen

好了具体操作如下:

官网:

yuicompressor-2.4.6.jar 下载地址 http://yuilibrary.com/downloads/#yuicompressor

YUIAnt.jar 下载地址 http://www.ubik-ingenierie.com/miscellanous/YUIAnt/

具体的相关代码如下:

  1. #css work dir
  2. commonCss.dir = css
  3. #js work dir
  4. commonJs.dir = js
  5. #build temp dir
  6. output.temp.dir = build
  7. #output files in the directory
  8. output.dir = ${output.temp.dir}_output
  9. #environment needs lib
  10. liblib = lib
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="Compress CSS-JS" default="compress" basedir=".">
  3. <property file="bulid.properties" />
  4. <path id="yuiClasspath">
  5. <fileset dir="${lib}">
  6. <include name="*.*" />
  7. </fileset>
  8. </path>
  9. <!-- #######################Init the environment of the tool ##########################-->
  10. <target name="init">
  11. <echo message="begin to init the init" />
  12. <echo message="delete all reference files." />
  13. <delete dir="${output.dir}" />
  14. <echo message="delete end" />
  15. <echo message="make the reference files." />
  16. <mkdir dir="${output.dir}" />
  17. <mkdir dir="${output.temp.dir}" />
  18. <echo message="make end." />
  19. </target>
  20. <!-- #######################Combine the css files             ##########################-->
  21. <target name="combinecss" depends="init" description="Combine common css files">
  22. <echo message="begin to combine the css files to one file." />
  23. <concat destfile="${output.temp.dir}/combined_css.css" encoding="UTF-8" append="false">
  24. <fileset dir="${commonCss.dir}">
  25. <include name="*.css" />
  26. </fileset>
  27. </concat>
  28. <echo message="combine end." />
  29. </target>
  30. <!-- #######################Combine the js files             ##########################-->
  31. <target name="combinejs">
  32. <echo message="begin to combine the js files to one file." />
  33. <concat destfile="${output.temp.dir}/all_source.js" encoding="utf-8" append="false">
  34. <fileset dir="${commonJs.dir}">
  35. <include name="*.js" />
  36. </fileset>
  37. </concat>
  38. <echo message="combine end." />
  39. </target>
  40. <!-- #######################Compress the js and css files  ##########################-->
  41. <target name="compress" depends="combinecss,combinejs" description="Compress">
  42. <echo message="begin to compress the css file." />
  43. <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
  44. <classpath>
  45. <path refid="yuiClasspath" />
  46. </classpath>
  47. </taskdef>
  48. <!-- first method compress the css files -->
  49. <yuicompress linebreak="10000000" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${output.dir}">
  50. <fileset dir="${output.temp.dir}">
  51. <include name="*.css" />
  52. </fileset>
  53. </yuicompress>
  54. <echo message ="compress the css end." />
  55. <!-- second method compress the js files-->
  56. <echo message ="begin to compress the js file." />
  57. <apply executable="java" parallel="false" failonerror="true">
  58. <fileset dir="${output.temp.dir}" includes="all_source.js" />
  59. <arg line="-jar" />
  60. <arg path="${lib}/yuicompressor-2.4.6.jar" />
  61. <arg line="--charset utf-8" />
  62. <arg line="-o ${output.dir}/combined_js.js" />
  63. <srcfile />
  64. </apply>
  65. <echo message ="compress the js end." />
  66. <delete dir="${output.temp.dir}" />
  67. </target>
  68. </project>
  1. @echo off
  2. echo ################################################
  3. echo ##########Tool Compress the js and css##########
  4. echo ################################################
  5. echo Please make sure your css and js in the css'directory and js'directory.
  6. echo If sure,please enter any button to continue the tool.
  7. pause
  8. call ant -buildfile compress.xml compress>build.log
  9. echo compress end
  10. pause

相关的文件我提供下载,感觉好的,就留言吧

使用YUI+Ant 实现JS CSS压缩的更多相关文章

  1. YUI+Ant 实现JS CSS压缩

    今天研究了一下YUI yahoo开源框架,感觉很猛啊. 于是乎我做了一个YUI的ant实现,网上好多关于bat的实现,我就另辟蹊径,出个关于这个的ant实现,嘿嘿独一无二的文章,如果转载的话,其注明作 ...

  2. 网站优化JS css压缩

    在nginx 中开启gzip压缩后,可以大大减少资js css 体积,原来200KB,压缩后只有66KB server{ gzip on; gzip_types text/plain applicat ...

  3. iis 发布asp.net mvc 网站时候js css 压缩问题,图片不加载问题

    一.JS CSS 自动压缩问题 默认情况下mvc这个框架会把css,js文件压缩成一个js或者css文件,一会发现只有一个<link href="/Content/css?v=ji3n ...

  4. 使用ant对JS/CSS 进行压缩以提高网站性能

    减少HTTP请求是优化网站速度的一个重要手段, 所以对javascript/css两种文件进行压缩或合并都是非常必要的. 这里介绍利用ANT来自动进行文件合并和压缩. 3.1. javascript文 ...

  5. gurnt js css 压缩合并

    package.json 文件 { "name":"my-project-name", "version":"0.0.1" ...

  6. JS/CSS 压缩的好处

    1.减小了文件的体积 2.减小了网络传输量和带宽占用 3.减小了服务器的处理的压力 4.提高了页面的渲染显示的速度

  7. Asp.Net使用Yahoo.Yui.Compressor.dll压缩Js|Css

    网上压缩css和js工具很多,但在我们的系统中总有特殊的地方.也许你会觉得用第三方的压缩工具很麻烦.我就遇到了这样问题,我不想在本地压缩,只想更新到服务器上去压缩,服务器压缩也不用备份之类的操作.于是 ...

  8. JS&CSS文件请求合并及压缩处理研究(五)

    接上篇.在我们最终调用 @Html.RenderResFile(ResourceType.Script) 或者 @Html.RenderResFile(ResourceType.StyleSheet) ...

  9. 利用YaHoo YUI实现Javascript CSS 压缩 分类: C# 2014-07-13 19:07 371人阅读 评论(0) 收藏

    网站优化时,往往需要对js文件,css文件进行压缩,以达到减少网络传输数据,减少网页加载时间:利用YaHoo的YUI可以实现Javascript,CSS,压缩,包括在线的js压缩和程序压缩,发现C#也 ...

随机推荐

  1. Redis实战(一)

    一.准备 Redis 是一个开源的使用ANSI C 语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value 数据库.Redis的出现,很大程度补偿了memcached这类key/valu ...

  2. Check whether a + b = c or not after removing all zeroes from a,b and c

    Check whether a + b = c or not after removing all zeroes from a,b and c Given two integers a and b, ...

  3. LCA:倍增与tarjan

    学了好久(一两个星期)都没彻底搞懂的lca,今天总算理解了.就来和大家分享下我自己的心得 首先,如果你还不懂什么是lca,出门左转自行百度 首先讲倍增 倍增的思想很简单,首先进行预处理,用一个深搜将每 ...

  4. 磁盘镜像分析工具Autopsy

    磁盘镜像分析工具Autopsy   Autopsy是Kali Linux预安装的一款磁盘镜像分析工具.该工具可以对磁盘镜像的卷和文件系统进行分析,支持Unix和Windows系统.Autopsy是一个 ...

  5. 【BZOJ 1016】 1016: [JSOI2008]最小生成树计数 (DFS|矩阵树定理)

    1016: [JSOI2008]最小生成树计数 Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树 ...

  6. luogu P1011 车站

    题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...

  7. BZOJ1018 堵塞的交通(线段树)

    题目很好明白,然后实现很神奇.首先如果考虑并查集的话,对于删边和加边操作我们无法同时进行.然后暴力分块的话,复杂度是O(n sqrt n) ,不是很优.于是看了题解,发现了线段树的神奇用途. 我们维护 ...

  8. POJ3710 Christmas Game 博弈论 sg函数 树的删边游戏

    http://poj.org/problem?id=3710 叶子节点的 SG 值为0:中间节点的SG值为它的所有子节点的SG值加1后的异或和. 偶环可以视作一个点,奇环视为一条边(连了两个点). 这 ...

  9. HDU1251 统计难题 trie树 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 找前缀数量 裸模板 #include<cstdio> #include<cstr ...

  10. 多个Fragment在屏幕翻转会重影问题的解决

    fragment使用add和hide而不用replace的方法添加到activity中,如果屏幕翻转可能会又add新的fragment进去,所以会重影. 如果有一个sparsearray保存fragm ...