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#也 ...
随机推荐
- MySQL Insert语句单个批次数量过多导致的CPU性能问题分析
[问题] 最近有台服务器比较频繁的CPU报警,表现的特征有CPU sys占比偏高,大量慢查询,大量并发线程堆积.后面开发对insert的相关业务限流后,服务器性能恢复正常. [异常期间线程处理情况] ...
- Python 学习经历分享
如果说 Java 是亲儿子的话,那么 Python 应该就是干儿子了.看了一下所有关于 Python 的笔记,我发现原来我在 4 月份的时候就已经涉足 Python 了,但是到目前为止才真正算做出了一 ...
- 「长乐集训 2017 Day10」划分序列 (二分 dp)
「长乐集训 2017 Day10」划分序列 题目描述 给定一个长度为 n nn 的序列 Ai A_iAi,现在要求把这个序列分成恰好 K KK 段,(每一段是一个连续子序列,且每个元素恰好属于一 ...
- [代码审计]eml企业通讯录管理系统v5.0 存在sql注入
0x00 前言 上周五的时候想练练手,随便找了个系统下载下来看看. 然后发现还有VIP版本,但是VIP要钱,看了一下演示站,貌似也没有什么改变,多了个导入功能?没细看. 搜了一下发现这个系统,压根就没 ...
- C# NPOCO 轻量级ORM框架(进阶)
继续翻译NPOCO wiki. 这篇将home上 下面的几个页面翻译. wiki地址:https://github.com/schotime/NPoco/wiki 上一篇: http://www.cn ...
- 【MPI】并行奇偶交换排序
typedef long long __int64; #include "mpi.h" #include <cstdio> #include <algorithm ...
- Tomcat CVE-2017-12615 远程上传漏洞复现
漏洞名称:CVE-2017-12615-远程代码执行漏洞 CVE-2017-12615:远程代码执行漏洞 当 Tomcat运行在Windows操作系统时,且启用了HTTP PUT请求方法(例如,将 r ...
- [HNOI2008]玩具装箱
OJ题号: BZOJ1010 思路: 斜率优化动态规划. 由题意得状态转移方程为$f_i=\displaystyle{\min_{j=0}^{i-1}}\{f_j+\left(i-j-1+\displ ...
- [SPOJ-BEADS]Glass Beads
来源: CE1998 题目大意: 求字符串最小表示. 思路: 字符串复制一遍接在后面,构建SAM,然后每次跑小的转移. 跑n次以后就跑到了最小表示的末尾,用该状态的len值减去n就是最小表示的起始位置 ...
- 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 ...