Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce production file size #152

Closed
3 of 8 tasks
dmethvin-gov opened this issue Jul 11, 2018 · 6 comments
Closed
3 of 8 tasks

Reduce production file size #152

dmethvin-gov opened this issue Jul 11, 2018 · 6 comments
Labels
[practice] engineering Engineering related work [status] not prioritized Not necessarily won't-fix but near-term out of scope. [type] debt Tech debt, refactors, maintenance issues

Comments

@dmethvin-gov
Copy link
Contributor

dmethvin-gov commented Jul 11, 2018

I've added webpack-bundle-size to the starter app and it generates output into public/stats/bundle.html on each production build showing the sizes of components in the bundle. I can't upload a picture of the web page it generates (GitHub uploads are blocked) so I'll summarize the main issues here. The biggest dependencies by size are:

Component Parsed size (KB) Pulled in via
Total 1001
moment 227 us-forms-system
styles.css 181 us-forms-system (and USWDS)
USFS JS code 119 us-forms-system
react-dom 101 react-jsonschema-form
lodash 55 us-forms-system and others
react-jsonschema-form 53 us-forms-system
raven-js 39 us-forms-system
react-scroll 24 us-forms-system

So the sorta-good news is that most of these are direct dependencies so we possibly have the ability to shrink or remove them. Here are my notes.

EDIT: A useful blog post series: https://www.contentful.com/blog/2017/11/13/put-your-webpack-bundle-on-a-diet-part-4/

@dmethvin-gov dmethvin-gov added [practice] engineering Engineering related work [type] debt Tech debt, refactors, maintenance issues labels Jul 11, 2018
@fatima-gov fatima-gov modified the milestone: 7/25 Hackathon Jul 12, 2018
@dmethvin-gov
Copy link
Contributor Author

Additional links for things to reduce size, e.g. removing React propTypes:
https://github.com/GoogleChromeLabs/webpack-libs-optimizations

More tips: https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

@dmethvin-gov
Copy link
Contributor Author

At the moment it looks like we're pulling down most if not all of USWDS. We may be able to get a smaller set of styles when/if we refactor to separate forms from the navigation and other things like the footer. The eQip prototype seems to have refactored the USWDS styles for form elements into separate files so there may be something to learn from there. That avoids including any styles of form elements you don't use.

@jcmeloni-usds
Copy link
Contributor

@dmethvin-gov @annekainicUSDS Is it correct to say "moment -- done w/ #258 and the rest is still an ongoing discussion"?

@annekainicUSDS
Copy link
Contributor

@jcmeloni-usds yep!

In regards to lodash, I saw some discussion in one of the Vets.gov channels recently about how lodash/fp is much less efficient than regular lodash. An example they provided was if you compare a bundle that just imports lodash/fp/uniqueId vs lodash/uniqueId, the fp version is 47kb and the regular version is 2.65kb. A quick solution for reducing the bundle size of lodash is just to use the regular version instead of fp. Not sure what impact that will make, but we should investigate it!

@dmethvin-gov
Copy link
Contributor Author

As I understand it, Redux requires any changes to the data store to be done by replacing with new data structures rather than mutating the old ones. That's how it knows whether the data changed, because it can use an inexpensive equality test to see if the objects are the same. The standard lodash mutates the incoming data for some operations so we can't use it everywhere. That difference on uniqueId is really strange though, not sure why there would be such a large difference in size.

@annekainicUSDS annekainicUSDS added the [status] not prioritized Not necessarily won't-fix but near-term out of scope. label Dec 27, 2018
@dmethvin-gov
Copy link
Contributor Author

Closing for now, we'll revisit once we do the refactoring in #57, #66, and #141.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[practice] engineering Engineering related work [status] not prioritized Not necessarily won't-fix but near-term out of scope. [type] debt Tech debt, refactors, maintenance issues
Projects
None yet
Development

No branches or pull requests

4 participants