Background
I recently shared the Elm compiler performance boosts we got from upgrading our largest application from 0.18 to 0.19 on Twitter:
In the replies, there was some discussion about output file sizes. I mentioned that I was using the google-closure-compiler
, but @evancz replied saying he got better results using uglifyjs
.
Evan suggested moving the discussion to Discourse:
UglifyJS vs Closure Compiler comparison
My project stats
- 88 modules get recompiled upon removing the
elm-stuff
directory and runningelm make
- The project is roughly 24,535 source lines of Elm code
- The output .js file after initial compilation is 54,259 lines
Output sizes
Below are the output sizes listed from largest to smallest. You can see that there is some disparity between uglifyjs
and google-closure-compiler
initially. The final result after gzip
is that the two are within 1% of one another in terms of size, with GCC being approximately 500 bytes smaller than the uglifyjs output.
Method | Gzip | Output Size |
---|---|---|
elm make |
No | 1728593 bytes |
elm make --optimize |
No | 1602466 bytes |
elm make --optimize + uglifyjs |
No | 386604 bytes |
elm make --optimize + google-closure-compiler |
No | 365266 bytes |
elm make --optimize + uglifyjs |
Yes | 109232 bytes |
elm make --optimize + google-closure-compiler |
Yes | 108702 bytes |
uglifyjs
configuration
This script is adapted from the script in Evanās post about optimizing Elm. I have not changed the arguments supplied at all. I am using the latest version of the uglify-js
package on npm (version 3.4.9).
#!/bin/sh
set -e
js="app.js"
min="app.uglify.min.js"
uglifyjs $js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9"ure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle --output=$min
echo " Initial size: $(cat $js | wc -c) bytes ($js)"
echo "Minified size: $(cat $min | wc -c) bytes ($min)"
echo " Gzipped size: $(cat $min | gzip -c | wc -c) bytes"
google-closure-compiler
configuration
Iām using the latest version of the google-closure-compiler
package on npm (version v20181210). There are no special arguments being provided.
#!/bin/sh
set -e
js="app.js"
min="app.closure.min.js"
google-closure-compiler --js=$js --js_output_file=$min
echo " Initial size: $(cat $js | wc -c) bytes ($js)"
echo "Minified size: $(cat $min | wc -c) bytes ($min)"
echo " Gzipped size: $(cat $min | gzip -c | wc -c) bytes"
Sharing your findings
Please feel free to share the results of your own minification findings, particularly if your results do not match up with the ones here.