Compile multiple times the same files

26 views
Skip to first unread message

TomaP

unread,
Jan 12, 2010, 2:24:08 PM1/12/10
to Closure Compiler Discuss
Hi,

When I compile multiple time my JS, the output is smaller the second
time :

java -jar compiler.jar --js=jquery.js --js_output_file=jquery.min.js
java -jar compiler.jar --js=jquery.min.js --
js_output_file=jquery.min2.js

jquery.min2.js is smaller than jquery.min.js

After that, the code size does not decrease.

Couldn't Closure shrink it to min2 the first time ?
Is there a reason for that difference ?

Thank you

Thomas
PS : I tested with jquery 1.4 RC1 ( http://jquery14.com/pre-release-2/jquery-14rc1
)

Robert Bowdidge

unread,
Jan 12, 2010, 2:31:35 PM1/12/10
to closure-comp...@googlegroups.com
Hi, Thomas,

One reason is that Closure Compiler assumes that your code uses dotted
properties when the name can safely be renamed, and quoted properties
when the name can't be renamed:


foo.propertyToRename = 1;
foo['propertyCannotBeRenamed'] = 2;

Closure Compiler also converts quoted property references to dotted
property references to save three bytes, so the output for the above
code would be:

foo.a = 1;
foo.propertyCannotBeRenamed = 2;

When you run it through the compiler again, Closure Compiler doesn't
realize that 'propertyCannotBeRenamed' is special, and assumes the
second is safe to rename:

foo.a = 1;
foo.b = 2;

Also, if Closure Compiler sees JSDoc comments with @license tags, it
assumes the text of that comment must appear in the final file. The
@license tag doesn't get included in the output, so if you re-
processed the file, the comment would be deleted.

Robert


Nick Santos

unread,
Jan 12, 2010, 2:49:45 PM1/12/10
to closure-comp...@googlegroups.com
On Tue, Jan 12, 2010 at 2:31 PM, Robert Bowdidge <bowd...@google.com> wrote:
> Hi, Thomas,
>
> One reason is that Closure Compiler assumes that your code uses dotted
> properties when the name can safely be renamed, and quoted properties when
> the name can't be renamed:

i don't think that default mode does property renaming?

has anybody checked what the actual difference is between the two
files? does jquery.min.js have a @license tag in it?

Nick

John Lenz

unread,
Jan 12, 2010, 9:04:06 PM1/12/10
to closure-comp...@googlegroups.com
I was able to reproduce this.  There is a difference of 17 bytes caused by two cases where an "if" statement is folded (one into an AND expression, and the other into a HOOK expression).

John Lenz

unread,
Jan 12, 2010, 9:26:34 PM1/12/10
to closure-comp...@googlegroups.com
What is strange about this is the using the jQuery's minimized release (which using Closure Compiler for 1.4rc1) is identical except for the license which is removed during the first compilation.  After it is only after that and recompiling that we see the additional changes occur.
Reply all
Reply to author
Forward
0 new messages