Angular application bundles using Rollup, Webpack and the Closure compiler
syntaxsuccess.com
syntaxsuccess.com
The downside to its age is that it likes to do things its own way; it's had a static module system since long before ES2015 modules or even CommonJS modules existed. It does have support for other module systems now, though. And as the article mentions, it performs optimizations far beyond what other JS tools do.
One of the big things people disliked about the compiler is that to get maximum optimizations out of it, you had to write your JS in a relatively static way, preferably with JSDoc type annotations.
This is less of a barrier now, I think; TypeScript has become quite popular in the front end community, and the Angular team has created TSickle[1], which allows the TypeScript compiler to output Closure annotated JS.
Webpack is a lot more capable, but also results in shipping a much larger code bundle to your users. This might not matter so much for desktop clients, but in many parts of the world, mobile users still have pretty restrictive data caps, and overages are very expensive.
It's an interesting case study in why developer UX is so important - Closure never really "fit in" with other tools, which I think really hurt its adoption.
It supports working with JavaScript libraries who are also compatible, or at the sacrifice of less optimizations, it lets you work with non compatible JavaScript libraries also.
For example for Angular, you just need to specify an extern file. It will still optimize parts of it, but it won't do symbol renaming. (Disclaimer, I've never actually tried to use Angular with CLJS, but I believe this is true)
For libraries which are completly non compatible, you can import them as foreign libraries and they'll just bypass the advanced compilation, but all your CLJS code and everything else which can be optimized will.
Here's a template to get you started with Angular2 and CLJS https://github.com/steveshogren/angular2-cljs
The webpack and Rollup experiments were done with uglify and gzip enabled. The numbers are based on the reported values in Chrome when running the code here: http://www.syntaxsuccess.com/rollup-bundle http://www.syntaxsuccess.com/webpack-bundle http://www.syntaxsuccess.com/closure-bundle
The uglify code was accidentally commented out in the source on Github, but I have fixed that now.
https://medium.com/@fpresencia/understanding-gzip-size-836c7...
Depending on the code, even if it seems quite large initially it might minimize and gzip quite well. Actually, automatic code generation is the perfect candidate for a good compression. One of the reasons is because this:
(function(module, __webpack_exports__, __webpack_require__) {})
Will become just: (function(a,b,c){})
Which is 5char/function difference with the other example shown in the article with uglify. It becomes negligible when we take into account gzip, since that will be stored only once and then it's just 5char difference overall. So an apparent "module, __webpack_exports__, __webpack_require__" x N becomes just 5bytes of difference in total.Probably not a concern for desktop/laptop users, but there are plenty of mobile devices out there with relatively slow processors and 1GB of RAM or less.
The main problem when we get to optimization is that it highly depends on the browser and version. Parse time is still important, but I'd argue that it's related to both file size and processing power needed, but still less important than both of those.
[0]: https://twitter.com/Rich_Harris/status/820304090332876800 [1]: https://github.com/cramforce/splittable
I haven't tried this myself, but it's worth noting that you can use closure with webpack: https://github.com/roman01la/webpack-closure-compiler
Hopefully it won't be long before frameworks still depending on html templates are mostly implementing them with es6 tagged template literals, which will make them available for compiler optimizations.
I meant more on like Angular implementing it's html templates using template literals and importing them into the runtime, making them inspectable. On second thought, it might be less a matter of the underlying logic and more a matter of when templates are evaluated
I'm on a team with a moderately large frontend written with the closure compiler, and we are looking forward to using other libraries on new projects.