5 ms·
One reason you don’t want a class for every component is that standard JS minifiers won’t compress method call names, but can compress imported function names.
by jitl 3y ago
One reason you don’t want a class for every component is that standard JS minifiers won’t compress method call names, but can compress imported function names. So the cost in the minified bundle between a class component and an equivalent function component is huge, multiplied out by the complexity of the component.
`this.handleClick` vs `c`.
I still use classes for building data structured but don’t think creating classes should be encouraged by a framework.
- Brybry 3y ago> So the cost in the minified bundle between a class component and an equivalent function component is huge Does this actually matter though? It's going to be gzipped anyway right?
- jitl 3y agoGzip compression will eliminate the repetition on the wire, but smaller uncompressed bundles will parse and start executing faster than larger bundles. For us this is most noticeable on Android which has the slowest hardware on average of all the platforms we support.
- Xt-6 3y agoThey can do it, it is just turned off by default and require more advanced configuration. https://github.com/terser/terser#cli-mangling-property-names---mangle-props https://github.com/terser/terser#cli-mangling-property-names...
- jitl 3y agoI don’t know any codebase that’s enabled these kinds of transforms because the compiler doesn’t know if a type’s properties will be introspected or iterated, so the transform is likely to break at runtime