Solvedangular compiler-cli ngfactory files are huge - make it more prone to mangle
✔️Accepted Answer
We already moved to webpack and split the app into chunks. So the initial payload went way down.
Regardless I tried the new view engine that landed in master today, scheduled for angular 4.0. Results are:
- total app size went down from 2.7MB to 1.7MB
- generated code went down from 1.8MB to 0.8MB
- build time (ngc + webpack) went down from 65sec. to 40sec.
Awesome! Can't wait to upgrade :)
Other Answers:
I've been thinking about this compiled template size thing some more. I wonder what is ultimately possible, in terms of keeping the performance of the generated code while reducing its size. My sense is that the underlying JavaScript engine JITs are quite aggressive and effective, and that there probably is opportunity to make the generated code tighter (by extracting duplication, having it rely on some helper classes need appear only once, etc.) while losing very little performance. But that is just a hunch.
Hopefully once the product is complete and shipped, and the correctness of all the key features is well-established and debugged (seems to be quite good now actually, although there are a great number of open issues in this tracker), some attention might shift back to making the pre-compiler output not only correct and fast, but also small.
There is a lot of unnecessary render empty text
this._text_7 = this.renderer.createText(this._el_6,'\n ',null);
using html minify before parsing templates reduced my app size by ~200kb
parse(....) {
const Minimize = require('minimize'),
minimize = new Minimize({ quotes: true, dom: { lowerCaseAttributeNames: false }});
if (template) {
template = minimize.parse(template);
}
if (templateUrl) {
templateUrl = minimize.parse(templateUrl);
}
....
}
I'm submitting a ... (check one with "x")
Current behavior
The *.ngfactory.ts files generated by
ngc
are huge. In my case 1.5MB in total (80 Components). And the code doesn't become much smaller with minify/mangle as there isthis.
before 95% of all statements.Example Component: gist.github.com/sod/049ce...
ngc
output for that component: gist.github.com/sod/ca6dc...If I transcode & mangle this factory alone, the output is 66kb for this one component.
Expected/desired behavior
More minify friendly output of
ngc
.