Even though modern browsers are able to stream the bundle as it arrives, it can still take a significant time before the first pixel is painted on the user's device. The bigger the bundle, the longer it can take before the engine reaches the line on which the first rendering call has been made. Until that time, the user has to stare at a blank screen.
We want to display data to the user as quickly as possible. A larger bundle leads to an increased amount of loading time, processing time, and execution time. It would be great if we could reduce the size of this bundle, in order to speed things up.
Instead of requesting one giant bundle that contains unnecessary code, we can split the bundle into multiple smaller bundles!
By bundle-splitting the application, we can reduce the time it takes to load, process and execute a bundle! By reducing the loading and execution time, we can reduce the time it takes before the first content has been painted on the user's screen, the First Contentful Paint (FCP), and the time it takes before the largest component has been rendered to the screen, the Largest Contentful Paint (LCP).
Although being able to see data on our screen is great, we don't just want to see the content. In order to have a fully functioning application, we want users to be able to interact with it as well! The UI only becomes interactive after the bundle has been loaded and executed. The time it takes before all content has been painted to the screen and has been made interactive, is called the Time To Interactive (TTI).
A bigger bundle doesn't necessarily mean a longer execution time. It could happen that we loaded a ton of code that the user won't even use! Maybe some parts of the bundle will only get executed on a certain user interaction, which the user may or may not do!
The engine still has to load, parse and compile code that's not even used on the initial render before the user is able to see anything on their screen. Although the parsing and compilation costs can be practically ignored due to the browser's performant way of handling these two steps, fetching a larger bundle than necessary can hurt the performance of your application. Users on low-end devices or slower networks will see a significant increase in loading time before the bundle has been fetched.
Instead of initially requesting parts of the code that don't have a high priority in the current navigation, we can separate this code from the code that's needed in order to render the initial page.
By bundle-splitting the large bundle into two smaller bundles,
and
, we reduce the initial loading time by fetching a smaller amount of data.
尽管现代浏览器能够在代码包到达时流式加载,但在用户设备上绘制第一个像素之前,仍可能需要相当长的时间。代码包越大,引擎执行到首次渲染调用代码行的时间就越长。在这之前,用户只能盯着空白屏幕。
我们希望尽快向用户显示内容。更大的代码包会导致加载时间、处理时间和执行时间增加。如果我们能缩小代码包的大小,就能加快这些流程。
与其请求一个包含不必要代码的大型代码包,我们可以将其拆分为多个更小的代码包!
通过对应用进行代码包拆分,我们可以缩短代码包的加载、处理和执行时间!通过减少加载和执行时间,我们能够缩短首次内容绘制(FCP)时间——即用户屏幕上首次显示内容的时间,以及最大内容绘制(LCP)时间——即最大组件渲染到屏幕上的时间。
虽然能在屏幕上看到内容很棒,但我们不希望用户只能_查看_内容。为了让应用完全可用,我们希望用户能够与应用_交互_!只有在代码包加载并执行完成后,UI才会变为可交互状态。所有内容绘制完成并可交互所需的时间称为交互时间(TTI)。
更大的代码包并不一定意味着更长的执行时间。有可能我们加载了大量用户根本不会用到的代码!比如代码包中的某些部分只有在特定用户交互时才会执行,而用户可能进行也可能不进行这些交互!
在用户能够看到屏幕上的任何内容之前,引擎仍需加载、解析和编译初始渲染中根本不会用到的代码。尽管浏览器处理这两个步骤的方式非常高效,解析和编译的成本几乎可以忽略,但获取不必要的大型代码包仍会损害应用性能。使用低端设备或网络较慢的用户会发现代码包获取前的加载时间显著增加。
我们可以将当前导航中优先级不高的代码部分与初始页面渲染所需的代码分离,而不是在初始请求时就加载这些低优先级代码。
通过将大型代码包拆分为两个更小的包——
和
——我们通过获取更少的数据来缩短初始加载时间。