Code Splitting Using Lazy Components and Suspense
Code splitting has been a significant part of React applications for many years, even before official support was included in the React API. The evolution of React has brought about APIs that are specifically designed to assist in code-splitting scenarios. Code splitting becomes crucial when dealing with large applications containing a vast amount of JavaScript code that needs to be delivered to a browser.
In the past, monolithic JavaScript bundles containing an entire application could cause usability issues due to long initial page load times. Thanks to code splitting, we now have much more granular control over how code is transferred from the server to the browser. This gives us ample opportunities to optimize load-time User Experience (UX).
In this chapter, we will revisit how to implement this in your React applications by using the lazy()
API and the Suspense
components. These features are very powerful tools in the...