Hello everybody. I have used Elm for about one year and now I’m migrating to 0.19. By the way, I find elm fascinating.
I am a bit confused about the use of the --optimize flag. I am using the Buttons example from elm-lang for this test. If “making” with --debug flag I get a debug.html file with size 107.597 bytes. Applying --optimize flag to elm make I get a production.html file with size 106.343 bytes.
I expected a more important reduction in size due to removal of non-used code. Is this normal or is just that I’m doing something wrong?
We haven’t converted our projects to 0.19 yet, but my guess is that the new version of the compiler automatically performs certain optimizations on simple programs. 107 bytes is really small, so my guess this is already quite optimized. I think you’ll see a bigger benefit of the --optimize flag when compiling a larger program (e.g. try compiling the elm-spa-example).
It is normal but you are not seeing the full benefits. You should minimize and gzip the final JS in order to evaluate. You can use elm-minify tool if you want quick minification without having to bother with the options of uglifyjs.
In the counter example, it goes from 9.04kb to about 6.39kb which is a 30% saving. The elm-spa-example savings is about 12%.
In any case, the non-used code is no longer put in the output so, --optimize does not help with that.
Then I think you’ll see more of the difference it makes. I was seeing reductions in the 5% to 10% range after the (compile => minify => gzip) process but I’m not sure what you’ll get on really small programs.
Just to close the question and complete the information for the future, these are the results compiling elm-spa-example, as @christian suggested. The .min.js is the result of applying elm-minify to the corresponding .js file.
compiling with --debug: js: 508.743 bytes, .min.js: 148.620 bytes
compiling without options: js: 384.660 bytes, .min.js: 107.987 bytes
compiling with --optimize: js: 370.448 bytes, .min.js: 92.915 bytes