使用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#也 ...
随机推荐
- 在LoadRunner中从数组类型的参数随机取值的方法
在LoadRunner中从数组类型的参数随机取值的方法 使用web_reg_save_param做关联后,有时候会有多个匹配值. 为了模仿用户行为随机取一个值为后续transcation所用,可以使用 ...
- Windows 如何远程登陆 Server 的 jupyter
jupyter 安装就不用赘述了,本示例以 Putty 为例,展示如何从本地 windows 系统调用远程的 jupyter notebook 并且在本地 Chrome 中打开的方法 1. 首先,ss ...
- TCP拥塞控制及连接管理
在阅读此篇之前,博主强烈建议先看看TCP可靠传输及流量控制. 一.TCP拥塞控制 在某段时间,若对网络中某资源的需求超过了该资源所能提供的可用部分,网络的性能就要变坏——产生拥塞(congestion ...
- /etc/default/useradd配置文件详解
/etc/default/useradd文件内容如下: [xf@xuexi ~]$ cat /etc/default/useradd # useradd defaults file GROUP=100 ...
- TCP/IP——IP网络协议简记
IP提供不可靠.无连接的数据报传送服务 不可靠:不保证IP数据报能成功到达目的地,当发生错误时,IP的做法是丢弃这个数据报,然后发送ICMP消息报给信息源. 无连接:IP不维护任何关于后续数据报的状态 ...
- C和指针之学习笔记(6)
第17章 经典数据结构类型 堆栈 堆栈接口提供三种基本的操作:push.pop 和 top. Push:把一个新值压入到堆栈的顶部. Pop: 只把顶部元素从堆栈中移除,它并不返回这个值. Top: ...
- 【BZOJ 4503】4503: 两个串 (FFT)
4503: 两个串 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 497 Solved: 226 Description 兔子们在玩两个串的游戏.给 ...
- BZOJ1086 SCOI2005王室联邦
想学树上莫队结果做了个树分块. 看完题后想到了菊花图的形状认为无解,结果仔细一瞧省会可以在外省尴尬 对于每一颗子树进行深搜,一旦遇到加在一起大小达到B则将它们并为一省,因为他子树搜完以后没有分出块的大 ...
- Eclipse下使用Stanford CoreNLP的方法
源码下载地址:CoreNLP官网. 目前release的CoreNLP version 3.5.0版本仅支持java-1.8及以上版本,因此有时需要为Eclipse添加jdk-1.8配置,配置方法如下 ...
- Makefile-filter和filter-out
filter:代表中目标串中找出符合匹配规则的. 示例: sources := foo.c bar.c baz.s ugh.h foo: $(sources) cc $(filter %.c %.s, ...