Plugin optimization patterns for faster startup

Apply these patterns when you develop or migrate a front-end plugin so that heavy interface code loads on-demand instead of at startup.

Each pattern keeps the plugin entry point lightweight and reduces the synchronous chunk that Red Hat Developer Hub downloads before the plugin registers its extensions. Use the following patterns to keep the plugin entry point lightweight.

Defer extension interfaces behind blueprint loaders

Lazy-load extension user interfaces through blueprint loaders

Return the component from an import() call inside the blueprint loader , and do not statically import the component in the same file. The bundler then places the component in an asynchronous chunk.

// Avoid: MyPage is statically imported, so it stays in the synchronous chunk.
import { MyPage } from './components/MyPage';
loader: async () => <MyPage />,

// Prefer: MyPage loads only when the extension is rendered.
loader: async () => {
  const { MyPage } = await import('./components/MyPage');
  return <MyPage />;
},
Avoid fake-asynchronous loaders
An async loader that references a statically imported component is not lazy-loaded. Make the dynamic import() the only reference to the component from the entry or extension-definition file.
Do not use Promise.resolve as a substitute for import()

Returning Promise.resolve({ Content: AlreadyImportedComponent }) looks asynchronous but does not create an asynchronous chunk, because the component is still statically imported. A components callback, such as the one on HomePageWidgetBlueprint , must call import() to defer the component.

// Prefer: the component loads only when the widget renders.
components: async () => {
  const { MyHomepageCard } = await import('./components/MyHomepageCard');
  return {
    Content: () => <MyHomepageCard />,
  };
},
Use conditional import() for mutually exclusive user interfaces

When a loader renders one of several components based on configuration, call import() inside each branch so that only the selected component loads.

loader: async () => {
  // layouts is provided by the extension configuration or inputs.
  if (layouts.length > 0) {
    const { LayoutSwitcher } = await import('../components/LayoutSwitcher');
    return <LayoutSwitcher layouts={layouts} />;
  }
  const { EntityContent } = await import('../components/EntityContent');
  return <EntityContent />;
},
Prefer a blueprint loader over a synchronous component
When a blueprint accepts both a component and a loader parameter, use loader. When a blueprint supports data-driven parameters, such as an icon name, a title, and a link, use those instead of a custom React component.

Defer blueprints that take a synchronous element or factory

Defer heavy dependencies behind API factories

ApiBlueprint registration is synchronous. When an API implementation depends on a large library, load the library inside the factory function with import() so that the dependency loads only when the API is first used. Cache the returned promise with the ??= operator so that repeated calls reuse the same asynchronous chunk.

this.contentPromise ??= import('./FormDecoratorContent');
Use thin lazy shells when a blueprint requires a synchronous element

Some blueprints, such as AppDrawerContentBlueprint and certain root element blueprints, take a synchronous element or component parameter rather than a loader . Wrap the heavy user interface in a small module that exports only a React.lazy and Suspense shell, and import that shell from the entry file instead of the real component tree.

The lazyDrawerUi.tsx file exports the lazy shell:

// lazyDrawerUi.tsx: the entry file imports only this shell.
import { lazy, Suspense } from 'react';

const LazyDrawerContent = lazy(() =>
  import('./DrawerContent').then(m => ({ default: m.DrawerContent })),
);

export const DrawerContentElement = (
  <Suspense fallback={null}>
    <LazyDrawerContent />
  </Suspense>
);

The alpha.tsx entry file imports the shell and passes it to the blueprint:

// alpha.tsx import { DrawerContentElement } from './lazyDrawerUi'; const MY_DRAWER_ID = 'my-plugin.drawer-content'; params: { id: MY_DRAWER_ID, element: DrawerContentElement }

Keep entry files and shared code lightweight

Keep page routers and layouts out of entry files
Import routers, layout components, and their child routes through import() inside a loader. A router that is statically imported pulls every route it references into the synchronous chunk.
Split reusable building blocks onto a separate entry
Expose shared components and utilities through a dedicated Module Federation entry so that consuming plugins load them as separate asynchronous chunks instead of inflating a single synchronous chunk.
Keep icons and navigation metadata dependency-free
Define icons, titles, and navigation metadata inline in the entry file, without importing heavy component modules. This metadata must be available synchronously for navigation to render.

To confirm that an optimization reduces the synchronous chunk, complete the following checks:

  1. Build the plugin with yarn backstage-cli package bundle .
  2. Open the generated bundle/dist/mf-manifest.json file to see which assets load synchronously and asynchronously, and open bundle/dist/mf-stats.json to compare the byte sizes of those chunks before and after your change.
  3. Confirm that the synchronous chunk is smaller and that the deferred code appears in an asynchronous chunk.
  4. Load the plugin in Red Hat Developer Hub and test the affected pages, menus, icons, translations, and sign-in flow to confirm that extensions still render.

To record the result, compare the synchronous and asynchronous chunk counts and sizes before and after your change, as in the following table:

Metric Before After Change

Synchronous chunks

-

-

-

Synchronous size

- KB

- KB

- KB

Asynchronous chunks

-

-

-

Asynchronous size

- KB

- KB

- KB