Not sure what’s the benefit over simply using async imports inside component declarations…
Cristi Jora
51

Hi Cristi, and thanks for the great feedback!

Definetely I should add a warning in my post that Webpack is going to create a chunk for every component. Usually I have my “willing-to-split” components in a different folder so I don’t create unnecessary chunks. Thanks!

However, Webpack may be creating a lot of chunks, but your app will only consume the necessary ones, so you might end up with a “messy” compiled application, but not a less performant one.

Regarding the async code in the component declaration, the main difference here is that you are assuming the name of the component you want to import. Using the pattern of the post you would be able to import components while using a prop. Your approach is quite similar to main second approach, but improved by using code splitting. Which is cool indeed!