简体   繁体   English

何时在 NextJS 应用程序中使用可加载组件?

[英]When to use loadable-components in NextJS app?

I'm trying to improve my site performance and the Google Chrome Lighthouse tells me to use loadable-components for ssr in order to "remove unused javascript".我正在尝试提高我的网站性能,而 Google Chrome Lighthouse 告诉我使用可加载组件进行 ssr 以“删除未使用的 javascript”。

What I found in the doc is it seems to be a library with useful functions for my case, eg: component splitting/ loading library.我在文档中发现它似乎是一个对我的案例具有有用功能的库,例如:组件拆分/加载库。

My question is:我的问题是:

  1. Does @loadable/component is really that good? @loadable/component 真的那么好吗?
  2. If it is good, should I use it for any component/library import?如果它很好,我应该将它用于任何组件/库导入吗?

Thank you!谢谢!

By default, Next.js splits your JavaScript into separate chunks for each route.默认情况下,Next.js 将您的 JavaScript 拆分为每个路由的单独块。 So when users load your application, Next.js only sends the code needed for the initial route.所以当用户加载你的应用程序时,Next.js 只发送初始路由所需的代码。

You can further optimize the loading process with code splitting on the component level using inbuilt next/dynamic您可以使用内置的next/dynamic在组件级别通过代码拆分进一步优化加载过程

Refer code splitting with dynamic imports for more details.有关更多详细信息,请参阅 使用动态导入进行 代码拆分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM