Uglify modifies code in minified builds

Antranig Basman antranig.basman at colorado.edu
Wed Nov 25 18:48:35 UTC 2015


I have read ahead in this thread (up to the current time) but thought 
I'd reply to the original message since it contains the relevant 
transcripts.

I'm wondering what the source of surprise is, "that the code was 
actually different" - isn't this exactly the behaviour we expect from a 
compressing minifier?

In the longish run (although, in practice, within the next year, 
resources permitting), what we want to enable is the use of SOURCE MAPS, 
which will enable (in theory) arbitrarily mangled versions of the source 
code to be debugged in all of our currently supported browsers. IE11 has 
introduced support for these which fills in the last missing piece. 
"uglify" is already capable of producing these:

https://github.com/gruntjs/grunt-contrib-uglify#source-maps

In future this will be entirely essential, since we plan to modularise 
the current "infusion" module into dozens of smaller npm modules, which 
we will then weave together at runtime by use of "browserify" - which is 
also capable of producing source maps. browserify is capable of 
deferring to several minification tools, of which "uglify" is one - via 
the interestingly named "uglifyify", etc.

If we are being impeded in our daily work by our build configuration, it 
might be a good time to start getting familiar with the source map 
technology and get an early insight into any problems it might highlight 
for our workflow.

If we don't have time for this, the 13K savings through disabling the 
extra optimisations seem neither here nor there - and having code 
without any whitespace appear in the debugger seems equivalently 
obstructive to having the optimised version you showed - even if Safari 
can deal with this, the other browsers can't. I would say that until 
we're prepared to deploy SOURCE MAPS, we should go with simple 
concatenation in our builds.

Cheers,

Antranig

On 25/11/2015 16:16, Justin Obara wrote:
>
>
> I was code reviewing FLUID-5759
> <https://github.com/fluid-project/infusion/pull/655> this morning and
> was looking into the change that was made. I was trying to step through
> the debugger to compare the change against what had previously been in
> the codebase. I went to the build site
> <http://build.fluidproject.org> to step through the tests. First off the
> code for Infusion is all minified; however, Safari does a decent job of
> separating the code to make it readable. Unfortunately I still could not
> find the part of the code I was looking for.
>
> After more digging I found the line I wanted but noticed that the code
> was actually different. I checked through the repository and confirmed
> that it was not an issue with the code being out of sync. After running
> some local builds it seems that the reason is the compression being done
> by Uglify <https://github.com/gruntjs/grunt-contrib-uglify>. It seems
> that be default most of the compression options
> <https://github.com/mishoo/UglifyJS2#compressor-options> are enabled.
>
> Example of the change:
>
> In source:
>              if (!fluid.isPrimitive(thisCompositeOptions.panels)) {
>                  fluid.each(thisCompositeOptions.panels, function
> (subpanelArray, pref) {
>                      subPanelList = subPanelList.concat(subpanelArray);
>                      if (pref !== "always") {
>                          fluid.each(subpanelArray, function (onePanel) {
>                              fluid.set(subPanelRenderOn, onePanel, pref);
>                          });
>                      }
>                  });
>              } else {
>                  subPanelList = thisCompositeOptions.panels;
>              }
>
> In minified:
>
> fluid.isPrimitive(thisCompositeOptions.panels)?subPanelList=thisCompositeOptions.panels:fluid.each(thisCompositeOptions.panels,function(subpanelArray,pref){subPanelList=subPanelList.concat(subpanelArray),"always"!==pref&&fluid.each(subpanelArray,function(onePanel){fluid.set(subPanelRenderOn,onePanel,pref)})})
>
>
> So far it doesn’t seem to have caused any issues, and they do disable
> “unsafe” compression options by default. In theory it should be safe to
> leave these on. However, it will mean we have a difference in code
> between the minified and source versions. Which, in the least, will make
> tracking down code between the two more difficult.
>
> What are you thoughts, should we keep the full compression or use
> smaller subset?
>
> infusion-all.js with full default compression options is 831KB
>
> infusion-all.js with the following options disabled, is 844KB
>
>                  compress: {
>                      sequences: false,
>                      dead_code: false,
>                      conditionals: false,
>                      booleans: false,
>                      unused: false,
>                      if_return: false,
>                      join_vars: false,
>                      drop_console: false
>                  }
>
> Thanks
> Justin
>
>
> _______________________________________________________
> fluid-work mailing list - fluid-work at lists.idrc.ocad.ca
> To unsubscribe, change settings or access archives,
> see http://lists.idrc.ocad.ca/mailman/listinfo/fluid-work
>



More information about the fluid-work mailing list