From harness-claude
Guides React dynamic imports with React.lazy, Suspense, and import() for code splitting to reduce bundle size and improve startup. Use for modals, routes, below-fold content, large libraries.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Load modules on demand to reduce initial bundle size and improve startup performance
Loads ES modules on demand with import() for code splitting and reduced initial bundle size. Use for routes, feature flags, heavy libraries, and conditional polyfills.
Optimizes React apps using memoization (React.memo, useMemo, useCallback), code splitting, virtualization, and concurrent rendering. Use for slow components, bundle size reduction, large datasets, and re-render prevention.
Provides step-by-step guidance, configurations, and best practices for code splitting in React, Vue, CSS frontend projects, focusing on performance optimization and accessibility.
Share bugs, ideas, or general feedback.
Load modules on demand to reduce initial bundle size and improve startup performance
React.lazy with a dynamic import() for component splitting:
const Modal = React.lazy(() => import('./Modal'));
<Suspense> with a fallback.import() directly:
const { heavyComputation } = await import('./heavy-utils');
const Chart = React.lazy(() => import(/* webpackChunkName: "chart" */ './Chart'));
const preload = () => import('./Modal');
<button onMouseEnter={preload} onClick={openModal}>Open</button>
Dynamic import is a JavaScript language feature (Stage 4). Bundlers create separate "chunks" for dynamically imported modules, loaded via <script> tags at runtime.
Chunk naming strategy:
Preloading: <link rel="preload"> or import() on hover/route-change triggers network fetch before the user needs it, hiding latency. Framework routers (Next.js, React Router) do this automatically for adjacent routes.
Measurement: Analyze bundle with vite build --report or webpack-bundle-analyzer before and after splitting.
https://patterns.dev/react/dynamic-import