{ loadable }
module from frontity
and then dynamically import the React component that you don't want to be loaded until it is strictly needed.loadable
with a dynamic import()
inside:import ... from
.state.comments.areOpened === false
.true
such as when, for example, you click a button to open the comments. At that moment the code for that React component is downloaded and executed.loadable
, the <HeavyComments>
component is included in the main bundle and loaded at the initial page load, even if the comments are never shown.