Overview
Async components allow you to split your application into smaller chunks and load components on demand. This is essential for optimizing bundle size and improving initial load performance.Basic Usage
Simple Async Component
Using in Templates
Function Signature
Loader Function
runtime-core/src/apiAsyncComponent.ts:21-25
defineAsyncComponent
runtime-core/src/apiAsyncComponent.ts:47-49
Advanced Options
AsyncComponentOptions Interface
runtime-core/src/apiAsyncComponent.ts:27-41
Full Options Example
runtime-core/src/apiAsyncComponent.ts:54-63
Loading States
Loading Component
Error Component
Error Handling
onError Callback
runtime-core/src/apiAsyncComponent.ts:83-91
Implementation Details
runtime-core/src/apiAsyncComponent.ts:75-116
Timeout Configuration
runtime-core/src/apiAsyncComponent.ts:210-220
Suspense Integration
With Suspense
Without Suspense
runtime-core/src/apiAsyncComponent.ts:181-184
Lazy Hydration
Async components support lazy hydration strategies:runtime-core/src/apiAsyncComponent.ts:34
Hydration Implementation
runtime-core/src/apiAsyncComponent.ts:124-155
Router Integration
Route-Level Code Splitting
Named Chunks
Testing Async Components
Mock Async Component
Test Loading State
Performance Optimization
Prefetching
Chunk Groups
Internal Implementation
isAsyncWrapper
runtime-core/src/apiAsyncComponent.ts:43-44
Wrapper Component
runtime-core/src/apiAsyncComponent.ts:119-251
Best Practices
- Use for heavy components that aren’t needed immediately
- Configure timeouts for slow networks
- Provide loading states for better UX
- Handle errors gracefully with retry logic
- Group related components in the same chunk
- Test loading states thoroughly
- Monitor chunk sizes to ensure effective splitting
- Use named chunks for better debugging
Common Use Cases
Modal Dialogs
Admin Panels
Heavy Charts
Related APIs
- Suspense - Learn about Suspense for async components
- Registration - Learn about component registration
- defineComponent - Learn about component definition