8

How does yui-compressor compress the javascript and css files?

 3 years ago
source link: https://www.codesd.com/item/how-does-yui-compressor-compress-the-javascript-and-css-files.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How does yui-compressor compress the javascript and css files?

advertisements

I am curious to understand what all things a compressor like yui-compressor do to compress a js or css file, what steps do i need to take if i want to write my own compressor.


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.

Source: http://developer.yahoo.com/yui/compressor/#work


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK