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

Code splitting #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

alfonsogarciacaro
Copy link
Contributor

@alfonsogarciacaro alfonsogarciacaro commented Apr 12, 2019

I think I found an easy way to split code with Fable! Latest Fable.React beta includes LazyComponent.FromExternalFunction which allows you to lazy load a component while keeping the type-safe reference. Can you please give it a try and check if it works? When you click on a question it should download another chunk (0.js).

@alfonsogarciacaro
Copy link
Contributor Author

Unfortunately the benefit is not so big because there's still a static dependency to the update function of the component. I wonder how we could prevent that, maybe we could also load the update function indirectly or somehow pass the update function together with the message?

@alfonsogarciacaro
Copy link
Contributor Author

alfonsogarciacaro commented Apr 12, 2019

At least, by moving the showdown import to Answer.View as this commit does the code for the markdown converter is removed from the vendors chunk and it's only loaded when loading Question.Show.

@alfonsogarciacaro alfonsogarciacaro changed the title Code splitting [WIP] Code splitting Apr 15, 2019
@alfonsogarciacaro alfonsogarciacaro changed the title [WIP] Code splitting Code splitting Apr 15, 2019
@alfonsogarciacaro
Copy link
Contributor Author

Webpack production bundles (hashes omitted):

No code splitting
app.js 135 KiB
vendors~app.js 329 KiB
Code splitting
2.js 6.31 KiB
3.js 70.8 KiB
app.js 172 KiB
vendors~app.js 259 KiB

2.js is the part taken away from app.js. Interestingly, app.js becomes bigger, I assume it's because tree shaking cannot be too aggressive when splitting chunks. The main benefit from code splitting in this case is 3.js, which contains the showdown library and is split from vendors~app.js. It won't be downloaded until is actually needed (when the user selects a question).

@MangelMaxime
Copy link
Owner

Hello @alfonsogarciacaro ,

sorry for the delay. Indeed being able to move some of the library load out of the vendors.js file is interesting.

I am just a bit worried if the increase of app.js is really due to tree shaking being less effective. Then for "real" world application it could become a problem and perhaps the vendor size reduction would be negate by the increase of app.js

@alfonsogarciacaro
Copy link
Contributor Author

Yes, it's not a fit-all solution. We can just keep the PR as an example. If I've time I'll try to investigate more the difference in the bundles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants