dart2js minification

174 views
Skip to first unread message

Cassio Tavares

unread,
Apr 22, 2014, 1:04:05 PM4/22/14
to mi...@dartlang.org
Why dart2js output is not so minified like other minification methods?\

What I mean is that if use another tool to minify dart2js output it will shrink even more. The first thing to note are the line breaks and spaces removal but it also changes variables names and other stuff. The problem for me is that these tools were messing with accents. My output is UTF-8.

Is this intentional, temporary or am I doing something wrong?

Thanks, 

Stephen Adams

unread,
Apr 22, 2014, 1:18:07 PM4/22/14
to General Dart Discussion
​It is intentional, although we are always looking improve dart2js.

Additional minification will break the code.​  Some names are generated according to a system, for example, getters are minfied to begin with 'g' so that they otherwise share the same name as the field.  This 'system' makes the minified getter names one character longer, but it allows getters to be generated programatically, so many getter methods are not part of the .js file at all.  If the dart2js output explicitly contained the getters, it would be quite a bit larger.

How much 'benefit' do you see?

 

Thanks, 

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Peter Ahé

unread,
Apr 22, 2014, 1:19:20 PM4/22/14
to mi...@dartlang.org
Some of the dart2js output isn't minified because it's emitted as text strings. We're currently working on fixing that. You should save very little from minifying that. 

As you may know, in JavaScript semi colons are somewhat optional, and are sometimes inserted when there is a new line. Dart2js takes advantage of this feature and emits new lines instead of semicolons. This is roughly equivalent, but is much easier to debug.

If you find that there is a tool that does a better job than dart2js itself, please report a bug at http://dartbug.com/new

Cheers,
Peter
--

Cassio Tavares

unread,
Apr 23, 2014, 3:52:09 PM4/23/14
to mi...@dartlang.org
Hi Stephen and Peter,

I did another test and for my surprise the re-minified output works just like the original.

The dart2js output has 1017 KB and the re-minified has 729 KB.

I've used this site to re-compress: http://jscompress.com/

I said that it was not working for me because of the UTF-8 accented characters but uploading the original file it works. I was copying and pasting before.

I'll wait your analysis to fill a bug or not.

Peter Ahé

unread,
Apr 23, 2014, 3:59:39 PM4/23/14
to mi...@dartlang.org
Sounds like dart2js has a problem. 

Did you compare the gzipped sizes?

Would it be possible for us to get a copy of your program?

Cheers,
Peter 

Dennis Kaselow

unread,
Apr 23, 2014, 4:02:49 PM4/23/14
to mi...@dartlang.org
Do you have

transformers:
- $dart2js:
    minify: true

in your pubspec.yaml? Since the 1.3 release pub build doesn't minify by default (doesn't run in release mode). This question has come up a few times already.

Dennis Kaselow

unread,
Apr 23, 2014, 4:04:52 PM4/23/14
to mi...@dartlang.org
There is a related open issue here: https://code.google.com/p/dart/issues/detail?id=18242

Cassio Tavares

unread,
Apr 23, 2014, 4:39:56 PM4/23/14
to mi...@dartlang.org
Dennis is right. 

I didn't know about that transformer option.

False alarm Peter!. :)

Cassio Tavares

unread,
Apr 23, 2014, 4:51:54 PM4/23/14
to mi...@dartlang.org
And I also have to say that dart2js minified output is much smaller

472 kb

Good Job!
Reply all
Reply to author
Forward
0 new messages