今天研究了一下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. MySQL Insert语句单个批次数量过多导致的CPU性能问题分析

    [问题] 最近有台服务器比较频繁的CPU报警,表现的特征有CPU sys占比偏高,大量慢查询,大量并发线程堆积.后面开发对insert的相关业务限流后,服务器性能恢复正常. [异常期间线程处理情况] ...

  2. Python 学习经历分享

    如果说 Java 是亲儿子的话,那么 Python 应该就是干儿子了.看了一下所有关于 Python 的笔记,我发现原来我在 4 月份的时候就已经涉足 Python 了,但是到目前为止才真正算做出了一 ...

  3. 「长乐集训 2017 Day10」划分序列 (二分 dp)

    「长乐集训 2017 Day10」划分序列 题目描述 给定一个长度为 n nn 的序列 Ai A_iA​i​​,现在要求把这个序列分成恰好 K KK 段,(每一段是一个连续子序列,且每个元素恰好属于一 ...

  4. [代码审计]eml企业通讯录管理系统v5.0 存在sql注入

    0x00 前言 上周五的时候想练练手,随便找了个系统下载下来看看. 然后发现还有VIP版本,但是VIP要钱,看了一下演示站,貌似也没有什么改变,多了个导入功能?没细看. 搜了一下发现这个系统,压根就没 ...

  5. C# NPOCO 轻量级ORM框架(进阶)

    继续翻译NPOCO wiki. 这篇将home上 下面的几个页面翻译. wiki地址:https://github.com/schotime/NPoco/wiki 上一篇: http://www.cn ...

  6. 【MPI】并行奇偶交换排序

    typedef long long __int64; #include "mpi.h" #include <cstdio> #include <algorithm ...

  7. Tomcat CVE-2017-12615 远程上传漏洞复现

    漏洞名称:CVE-2017-12615-远程代码执行漏洞 CVE-2017-12615:远程代码执行漏洞 当 Tomcat运行在Windows操作系统时,且启用了HTTP PUT请求方法(例如,将 r ...

  8. [HNOI2008]玩具装箱

    OJ题号: BZOJ1010 思路: 斜率优化动态规划. 由题意得状态转移方程为$f_i=\displaystyle{\min_{j=0}^{i-1}}\{f_j+\left(i-j-1+\displ ...

  9. [SPOJ-BEADS]Glass Beads

    来源: CE1998 题目大意: 求字符串最小表示. 思路: 字符串复制一遍接在后面,构建SAM,然后每次跑小的转移. 跑n次以后就跑到了最小表示的末尾,用该状态的len值减去n就是最小表示的起始位置 ...

  10. hdu 4025 Equation of XOR 状态压缩

    思路: 设: 方程为 1*x1 ^ 1*x2 ^ 0*x3 = 0; 0*x1 ^ 1*x2 ^ 1*x3 = 0; 1*x1 ^ 0*x2 ^ 0*x3 = 0 把每一列压缩成一个64位整数,因为x ...