使用YUI+Ant 实现JS CSS压缩
今天研究了一下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/
具体的相关代码如下:
- #css work dir
- commonCss.dir = css
- #js work dir
- commonJs.dir = js
- #build temp dir
- output.temp.dir = build
- #output files in the directory
- output.dir = ${output.temp.dir}_output
- #environment needs lib
- liblib = lib
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="Compress CSS-JS" default="compress" basedir=".">
- <property file="bulid.properties" />
- <path id="yuiClasspath">
- <fileset dir="${lib}">
- <include name="*.*" />
- </fileset>
- </path>
- <!-- #######################Init the environment of the tool ##########################-->
- <target name="init">
- <echo message="begin to init the init" />
- <echo message="delete all reference files." />
- <delete dir="${output.dir}" />
- <echo message="delete end" />
- <echo message="make the reference files." />
- <mkdir dir="${output.dir}" />
- <mkdir dir="${output.temp.dir}" />
- <echo message="make end." />
- </target>
- <!-- #######################Combine the css files ##########################-->
- <target name="combinecss" depends="init" description="Combine common css files">
- <echo message="begin to combine the css files to one file." />
- <concat destfile="${output.temp.dir}/combined_css.css" encoding="UTF-8" append="false">
- <fileset dir="${commonCss.dir}">
- <include name="*.css" />
- </fileset>
- </concat>
- <echo message="combine end." />
- </target>
- <!-- #######################Combine the js files ##########################-->
- <target name="combinejs">
- <echo message="begin to combine the js files to one file." />
- <concat destfile="${output.temp.dir}/all_source.js" encoding="utf-8" append="false">
- <fileset dir="${commonJs.dir}">
- <include name="*.js" />
- </fileset>
- </concat>
- <echo message="combine end." />
- </target>
- <!-- #######################Compress the js and css files ##########################-->
- <target name="compress" depends="combinecss,combinejs" description="Compress">
- <echo message="begin to compress the css file." />
- <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
- <classpath>
- <path refid="yuiClasspath" />
- </classpath>
- </taskdef>
- <!-- first method compress the css files -->
- <yuicompress linebreak="10000000" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${output.dir}">
- <fileset dir="${output.temp.dir}">
- <include name="*.css" />
- </fileset>
- </yuicompress>
- <echo message ="compress the css end." />
- <!-- second method compress the js files-->
- <echo message ="begin to compress the js file." />
- <apply executable="java" parallel="false" failonerror="true">
- <fileset dir="${output.temp.dir}" includes="all_source.js" />
- <arg line="-jar" />
- <arg path="${lib}/yuicompressor-2.4.6.jar" />
- <arg line="--charset utf-8" />
- <arg line="-o ${output.dir}/combined_js.js" />
- <srcfile />
- </apply>
- <echo message ="compress the js end." />
- <delete dir="${output.temp.dir}" />
- </target>
- </project>
- @echo off
- echo ################################################
- echo ##########Tool Compress the js and css##########
- echo ################################################
- echo Please make sure your css and js in the css'directory and js'directory.
- echo If sure,please enter any button to continue the tool.
- pause
- call ant -buildfile compress.xml compress>build.log
- echo compress end
- pause
相关的文件我提供下载,感觉好的,就留言吧
- YUICompressor.zip (1.5 MB)
使用YUI+Ant 实现JS CSS压缩的更多相关文章
- YUI+Ant 实现JS CSS压缩
今天研究了一下YUI yahoo开源框架,感觉很猛啊. 于是乎我做了一个YUI的ant实现,网上好多关于bat的实现,我就另辟蹊径,出个关于这个的ant实现,嘿嘿独一无二的文章,如果转载的话,其注明作 ...
- 网站优化JS css压缩
在nginx 中开启gzip压缩后,可以大大减少资js css 体积,原来200KB,压缩后只有66KB server{ gzip on; gzip_types text/plain applicat ...
- iis 发布asp.net mvc 网站时候js css 压缩问题,图片不加载问题
一.JS CSS 自动压缩问题 默认情况下mvc这个框架会把css,js文件压缩成一个js或者css文件,一会发现只有一个<link href="/Content/css?v=ji3n ...
- 使用ant对JS/CSS 进行压缩以提高网站性能
减少HTTP请求是优化网站速度的一个重要手段, 所以对javascript/css两种文件进行压缩或合并都是非常必要的. 这里介绍利用ANT来自动进行文件合并和压缩. 3.1. javascript文 ...
- gurnt js css 压缩合并
package.json 文件 { "name":"my-project-name", "version":"0.0.1" ...
- JS/CSS 压缩的好处
1.减小了文件的体积 2.减小了网络传输量和带宽占用 3.减小了服务器的处理的压力 4.提高了页面的渲染显示的速度
- Asp.Net使用Yahoo.Yui.Compressor.dll压缩Js|Css
网上压缩css和js工具很多,但在我们的系统中总有特殊的地方.也许你会觉得用第三方的压缩工具很麻烦.我就遇到了这样问题,我不想在本地压缩,只想更新到服务器上去压缩,服务器压缩也不用备份之类的操作.于是 ...
- JS&CSS文件请求合并及压缩处理研究(五)
接上篇.在我们最终调用 @Html.RenderResFile(ResourceType.Script) 或者 @Html.RenderResFile(ResourceType.StyleSheet) ...
- 利用YaHoo YUI实现Javascript CSS 压缩 分类: C# 2014-07-13 19:07 371人阅读 评论(0) 收藏
网站优化时,往往需要对js文件,css文件进行压缩,以达到减少网络传输数据,减少网页加载时间:利用YaHoo的YUI可以实现Javascript,CSS,压缩,包括在线的js压缩和程序压缩,发现C#也 ...
随机推荐
- Redis实战(一)
一.准备 Redis 是一个开源的使用ANSI C 语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value 数据库.Redis的出现,很大程度补偿了memcached这类key/valu ...
- 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, ...
- LCA:倍增与tarjan
学了好久(一两个星期)都没彻底搞懂的lca,今天总算理解了.就来和大家分享下我自己的心得 首先,如果你还不懂什么是lca,出门左转自行百度 首先讲倍增 倍增的思想很简单,首先进行预处理,用一个深搜将每 ...
- 磁盘镜像分析工具Autopsy
磁盘镜像分析工具Autopsy Autopsy是Kali Linux预安装的一款磁盘镜像分析工具.该工具可以对磁盘镜像的卷和文件系统进行分析,支持Unix和Windows系统.Autopsy是一个 ...
- 【BZOJ 1016】 1016: [JSOI2008]最小生成树计数 (DFS|矩阵树定理)
1016: [JSOI2008]最小生成树计数 Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树 ...
- luogu P1011 车站
题目描述 火车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上.下车,但上.下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人.从第3站起( ...
- BZOJ1018 堵塞的交通(线段树)
题目很好明白,然后实现很神奇.首先如果考虑并查集的话,对于删边和加边操作我们无法同时进行.然后暴力分块的话,复杂度是O(n sqrt n) ,不是很优.于是看了题解,发现了线段树的神奇用途. 我们维护 ...
- POJ3710 Christmas Game 博弈论 sg函数 树的删边游戏
http://poj.org/problem?id=3710 叶子节点的 SG 值为0:中间节点的SG值为它的所有子节点的SG值加1后的异或和. 偶环可以视作一个点,奇环视为一条边(连了两个点). 这 ...
- HDU1251 统计难题 trie树 简单
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 找前缀数量 裸模板 #include<cstdio> #include<cstr ...
- 多个Fragment在屏幕翻转会重影问题的解决
fragment使用add和hide而不用replace的方法添加到activity中,如果屏幕翻转可能会又add新的fragment进去,所以会重影. 如果有一个sparsearray保存fragm ...