ESC之ESC.wsf可以实现javascript的代码压缩附使用方法第2/5页
更新时间:2007年05月07日 00:00:00 作者:
可以对javascript的大小进行压缩。使javascript的加载速度变快。
Crunching, level by level
Level 0 :: No compression
No compression done. Basically a content transfer/append from input(s) to output. This level is mainly used for tracking down problems occuring to scripts after been shoved through the variable substitution engine.
Level 1 :: Comment removal
ESC removes empty lines (\r?\n)+, single and multi-line and single-line comments (//..., /* ... */) and trailing whitespace. [ \t]+\r?\n
Level 2 :: Whitespace removal
Any occurance of space and tabs (\s\t\r) are removed from the infile(s). This is the default compression-level if none is supplied.
Level 3 :: Newline removal
Newlines (\r?\n) are removed. ESC do not like sloppy written code and will at this level punish you for it by producing a very tight, human unreadable, uninpretable chunk o' chars :) So remember, *ALWAYS* terminate your statements with semi-colons (';'). If you come from a C/C++ bg you have probably been taught this the hard way by an evercroaking compiler. If not for getting your script thru ESC, so start doing it anyway for good ol' programming style.
Level 4 :: Variable substitution
(variable substitution mode, identical to options '-l 3 -$') Additionally to level 3, ESC will run your script(s) through the variable substitution engine. This will certainly break your scripts at the first try, but with a little fiddling around and once you understand how the substitution scheme works, this thing rule since it will save you another extra 5-20% bytewise depending on your coding style. Variable-names less than 3 chars are not affected. Before you try running ESC with variable substitution enabled, I advice you to carefully read the other sections in this manual about the pros and cons, thinking session-dependencies and the known caveats of variable crunching with ESC. Your specific situation in terms of namespaces, shared variables or the design/architecture of your scripts may make it difficult, even impossible to combine with this technique whereas you'll have to stick with level 3.
相关文章
PhantomJS快速入门教程(服务器端的 JavaScript API 的 WebKit)
Phantom JS是一个服务器端的 JavaScript API 的 WebKit。其支持各种Web标准: DOM 处理, CSS 选择器, JSON, Canvas, 和 SVG2015-08-08


最新评论