今天研究了一下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. 在LoadRunner中从数组类型的参数随机取值的方法

    在LoadRunner中从数组类型的参数随机取值的方法 使用web_reg_save_param做关联后,有时候会有多个匹配值. 为了模仿用户行为随机取一个值为后续transcation所用,可以使用 ...

  2. Windows 如何远程登陆 Server 的 jupyter

    jupyter 安装就不用赘述了,本示例以 Putty 为例,展示如何从本地 windows 系统调用远程的 jupyter notebook 并且在本地 Chrome 中打开的方法 1. 首先,ss ...

  3. TCP拥塞控制及连接管理

    在阅读此篇之前,博主强烈建议先看看TCP可靠传输及流量控制. 一.TCP拥塞控制 在某段时间,若对网络中某资源的需求超过了该资源所能提供的可用部分,网络的性能就要变坏——产生拥塞(congestion ...

  4. /etc/default/useradd配置文件详解

    /etc/default/useradd文件内容如下: [xf@xuexi ~]$ cat /etc/default/useradd # useradd defaults file GROUP=100 ...

  5. TCP/IP——IP网络协议简记

    IP提供不可靠.无连接的数据报传送服务 不可靠:不保证IP数据报能成功到达目的地,当发生错误时,IP的做法是丢弃这个数据报,然后发送ICMP消息报给信息源. 无连接:IP不维护任何关于后续数据报的状态 ...

  6. C和指针之学习笔记(6)

    第17章 经典数据结构类型 堆栈 堆栈接口提供三种基本的操作:push.pop 和 top. Push:把一个新值压入到堆栈的顶部. Pop: 只把顶部元素从堆栈中移除,它并不返回这个值. Top: ...

  7. 【BZOJ 4503】4503: 两个串 (FFT)

    4503: 两个串 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 497  Solved: 226 Description 兔子们在玩两个串的游戏.给 ...

  8. BZOJ1086 SCOI2005王室联邦

    想学树上莫队结果做了个树分块. 看完题后想到了菊花图的形状认为无解,结果仔细一瞧省会可以在外省尴尬 对于每一颗子树进行深搜,一旦遇到加在一起大小达到B则将它们并为一省,因为他子树搜完以后没有分出块的大 ...

  9. Eclipse下使用Stanford CoreNLP的方法

    源码下载地址:CoreNLP官网. 目前release的CoreNLP version 3.5.0版本仅支持java-1.8及以上版本,因此有时需要为Eclipse添加jdk-1.8配置,配置方法如下 ...

  10. Makefile-filter和filter-out

    filter:代表中目标串中找出符合匹配规则的. 示例: sources := foo.c bar.c baz.s ugh.h foo: $(sources) cc $(filter %.c %.s, ...