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#也 ...
随机推荐
- java I/O流类概述
java I/O流类概述
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) F. High Cry(思维 统计)
F. High Cry time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- springboot项目打war包部署到服务器(eclipse & gradle环境)
1.右键项目run as -> run configurations,打开Run configurations弹出框 2.右键Gradle Project -> New Configur ...
- hash课堂测试补分博客
题目要求: 开放地址法: 概念: 所谓的开放定址法就是一旦发生了冲突,就去寻找下一个空的散列地址,只要散列表足够大,空的散列地址总能找到,并将记录存入. 它的公式为: 解题过程(在下图中): 拉链法: ...
- 如何在java中跳出当前多重嵌套循环?有几种方法?
如何在java中跳出当前多重嵌套循环?有几种方法? - 两种方法 - 1.在外层循环定义标记 ok: for(int i=0;i<100;i++){ ...
- NGINX如何反向代理Tomcat并且实现Session保持
简介 LNMT=Linux+Nginx+MySQL+Tomcat: Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器: 在中小型系统和并发访问用户不是很多的场合下被 ...
- ubuntu 自动获取ip
$sudo dhclient -r $sudo dhclient $sudo dhclient eth0
- jquery 图片预加载
/图片无序预加载 (function($){ function Preload(imgs,fns){ this.imgs=(typeof imgs==="string")?[img ...
- 模仿JQuery 的添加多个事件的原理
var jquery=function(dom){ var obj={ ready:function(fn){ if(typeof dom.onload=="function"){ ...
- [Servlet]什么是Servlet
什么是Servlet Servlet是JavaEE三大组建之中的一个,是使用Java语言编写server端的程序,主要用来处理Web应用程序中的请求-响应. Servlet并没有main之类的执行方法 ...