YUICompressorCSSMin

Honored to be a part of the YUI project, I am now helping with the maintenance of the CSSMin part of the YUICompressor. My changes are now part of the trunk on github, so I'm official. Next on the agenda is documenting the thing, so that's what I'll try to do here, maybe in a few posts. You know, divide and conquer.

有幸成为一部分YUI项目,我现在与维护CSSMin部分帮助的YUICompressor 。 我的更改现在是github上的一部分,所以我是官方的。 议程上的下一个步骤是记录下来,这就是我在这里可能会尝试做的事情,也许是在几篇文章中。 你知道,分而治之。

PHP,Java和JavaScript端口 (PHP, Java and a JavaScript port)

Originally written in PHP by Isaac Schlueter and ported to Java by Julien Lecomte, CSSMin got a JavaScript port by yours truly some time ago. Because, after all, JavaScript is the language of the web, isn't it?

CSSMin最初由Isaac Schlueter用PHP编写,并由Julien Lecomte移植到Java,实际上在一段时间之前,CSSMin就获得了JavaScript移植。 因为毕竟JavaScript是网络的语言,不是吗?

You can play with the latest git version of the JS port online here.

您可以在此处在线使用JS端口的最新git版本。

I'm also happy to report that the JS port is now used in PageSpeed and YSlow (as you probably know Firefox extensions are written in JavaScript)

我也很高兴地报告JS端口已在PageSpeedYSlow中使用(您可能知道Firefox扩展是用JavaScript编写的)

Page Speed
YSlow

建造 (Building)

If you want to play on your own with the source version of YUICompressor without waiting for the next release, you can build it like so:

如果您想独自使用源代码版本的YUICompressor播放而无需等待下一个版本,则可以这样构建:

  1. Checkout or download the code from http://github.com/yui/yuicompressor/

    检出或从http://github.com/yui/yuicompressor/下载代码

  2. Navigate to the root yuicompressor/ directory

    导航到yuicompressor/根目录

  3. Type ant and hit enter

    输入ant并按Enter

In order for this to work you need a somewhat recent Java SDK installed and also Ant running. (On the Mac, just do port install apache-ant to get Ant)

为了使其正常工作,您需要安装一些最新的Java SDK并运行Ant 。 (在Mac上,只需执行port install apache-ant即可获得Ant)

This is for the Java version, the JS version needs no building, of course.

这是针对Java版本的,而JS版本当然不需要构建。

测验 (Tests)

There's a bunch of new tests now (and if you want to contribute to the project, you can always write more tests and test cases for any bugs), you can run them with the suite script that Isaac wrote:

现在有很多新测试(如果您想为项目做贡献,您可以随时编写更多测试和测试用例来解决任何错误),可以使用Isaac编写的套件脚本来运行它们:

  1. cd tests/

    cd tests/

  2. ./suite.sh

    ./suite.sh

One thing I added (and loved it) is to run the tests using the JS port as well. Since the JS min part is using Mozilla's Rhino (slightly modified), Rhino is part of the code. So I'm using this already available JavaScript interpreter to run the JS port. Convenient.

我添加(并喜欢)的一件事是也使用JS端口运行测试。 由于JS min部分使用的是Mozilla的Rhino (稍作修改),因此Rhino是代码的一部分。 所以我正在使用这个已经可用JavaScript解释器来运行JS端口。 方便。

The procedure to write new tests is simple:

编写新测试的过程很简单:

  1. Create source CSS file in the tests/ directory, e.g. new-test.css

    tests/目录中创建源CSS文件,例如new-test.css

  2. Create a new file with the expected result and name it with a .min extension, e.g. new-test.css.min

    创建具有预期结果的新文件,并以.min扩展名命名,例如new-test.css.min

You can use the handy-dandy online version to help with the tests creation.

您可以使用便捷的在线版本来帮助创建测试。

下次 (Next time)

With those details out of the way, the next time I'll talk more about the different things that CSSMin does to your CSS code. Thanks for reading!

有了这些细节,下一次我将更多地讨论CSSMin对您CSS代码所做的不同操作。 谢谢阅读!

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/yuicompressor-cssmin/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
雅虎推出的一款javascript压缩工具。有JAVA版本和.NET版本。 yuicompressor-2.4.2.jar yuicompressor-2.4.7.jar jsZip.exe yuicompressor yui compressor js压缩工具 javascript压缩工具 css压缩工具 ------------------------------------ //压缩JS java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 -v src.js > packed.js //压缩CSS java -jar yuicompressor-2.4.2.jar --type css --charset utf-8 -v src.css > packed.css 语法: java -jar yuicompressor-x.y.z.jar [options] [input file] 通用参数: -h, --help 显示帮助信息 --type <js|css> 指定输入文件的文件类型 --charset <charset> 指定读取输入文件使用的编码 --line-break <column> 在指定的列后插入一个 line-bread 符号 -v, --verbose 显示info和warn级别的信息 -o <file> 指定输出文件。默认输出是控制台。 javascript专用参数: --nomunge 只压缩, 不对局部变量进行混淆。 --preserve-semi 保留所有的分号。 --disable-optimizations 禁止优化。 举例: 将yuicompressor-2.4.2.jar 放在c:下,将editor.js放在c:盘下。 将editor.js进行压缩 命令为: C:\java -jar yuicompressor-2.4.2.jar editor.js -o editor2.js 参数说明: yuicompressor-2.4.2.jar 为工具包jar editor.js为要压缩的js -o editor2.js为压缩完成后的文件名 压缩率: 对resources下js文件夹里163个js文件进行压缩 压缩前4.13MB 压缩后2.89MB 混淆率: 较高 一个windows下的批量处理脚本: @echo off ::设置YUI Compressor启动目录 SET YUIFOLDER=C: ::设置你的JS和CSS根目录,脚本会自动按树层次查找和压缩所有的JS和CSS SET JSFOLDER=D:\1 echo 正在查找 JavaScript, CSS ... chdir /d %JSFOLDER% for /r . %%a in (*.js *.css) do ( @echo 正在压缩 %%~a ... @java -jar %YUIFOLDER%\yuicompressor-2.4.2.jar --charset UTF-8 %%~fa -o %%~fa ) echo 完成! pause & exi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值