javascript - 压缩 javascript 和 css 文件的 yui-compressor 是如何工作的?

标签 javascript css yui-compressor

我很想知道像 yui-compressor 这样的压缩器在压缩 js 或 css 文件时所做的所有事情,如果我想编写自己的压缩器,我需要采取哪些步骤。

最佳答案

The YUI Compressor is written in Java (requires Java >= 1.4) and relies on Rhino to tokenize the source JavaScript file. It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, omitting as many white space characters as possible, and replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate (in the face of evil features such as eval or with, the YUI Compressor takes a defensive approach by not obfuscating any of the scopes containing the evil statement) The CSS compression algorithm uses a set of finely tuned regular expressions to compress the source CSS file. The YUI Compressor is open-source, so don't hesitate to look at the code to understand exactly how it works.

来源:http://developer.yahoo.com/yui/compressor/#work

关于javascript - 压缩 javascript 和 css 文件的 yui-compressor 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412221/

相关文章:

javascript - 从 master 访问 worker 环境(Node.js 集群)

javascript - 使用 javascript 的 Discord 机器人 .sendMessage 不是函数

html - 应用 Bootstrap 时订单进度条被破坏

html - 我怎样才能用 CSS 重现这个?

javascript - Maven YUI 压缩机 : compress after aggregation

javascript - YUI Compressor 和 "use strict"提示

javascript - 自动化 Eclipse "Yui Compressor..."

javascript - 我写了一个 jquery 'lightbox' 风格的函数,但我正在努力在灯箱左/右创建无缝图像循环

javascript - 你能为我分解这个字符串操作函数吗? (JS)

javascript - jQuery UI 对话框加载 HTML 标题