Home App Docs Blog Github

Lazy loading Builder components

Builder components can be lazy loaded such that they can be used in any Builder.io but only downloaded to a browser when used (via code splitting).

To accomplish this, we need to separate our components and configuration into two separate files.

You can see an example of this using NextJS here


import LargeLibraryComponent from 'large-library'
export function MyComponent() { return <LargeLibraryComponent /> }


import { Builder } from '@builder.io/react';
import dynamic from 'next/dynamic';

// This code will only be fetched when this component is used on a page
const LazyMyComponent = dynamic(() =>
    (mod) => mod.AccordionComponent,

  { name: 'MyComponent '},

In this example we use Next.js, but you can also use this same methodology with Loadable or Suspense as well.

You can also accomplish lazy loading for our @builder.io/widgets package as seen in this example as well. See more info here