KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
🖖

Vue

Topic Hub & Articles

Vue Intro

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Get Started

10 min

Vue Directives

10 min

Vue Events

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Forms

10 min

Vue Components

10 min

Vue Props

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Methods

10 min

Vue Computed Properties

10 min

Vue Watchers

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Class and Style Bindings

10 min

Vue Conditional Rendering

10 min

Vue List Rendering

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Template Syntax

10 min

Vue Teleport

10 min

Vue Suspense

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Transitions

10 min

Vue Mixins

10 min

Vue Custom Directives

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Plugins

10 min

Vue Slots

10 min

Vue Provide / Inject

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Dynamic Components

10 min

Vue Async Components

10 min

Composition API Intro

10 min

Recap Quiz

Gated

Milestone Assessment

ref vs reactive

10 min

Lifecycle Hooks

10 min

Dependency Injection

10 min

Recap Quiz

Gated

Milestone Assessment

Computed and Watch

10 min

Template Refs

10 min

Composable Functions

10 min

Script Setup

10 min

Progress
0%

0 / 32 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
VueVue Tutorial
Lesson

Vue Async Components

10 min reading
Free Course

Vue Async Components: Code Splitting with defineAsyncComponent

Vue async components let you split large parts of your application into separate JavaScript chunks that load only when needed. Using defineAsyncComponent() with a dynamic import(), Vite bundles heavy widgets separately so your initial page loads faster.

This approach works best for components users do not see right away, such as rich text editors, interactive charts, PDF viewers, or admin settings modals.

flowchart LR
    Main["Initial App Bundle"] --> Action["User Clicks Show Chart"]
    Action --> Fetch["Lazy Fetch HeavyChart.js Chunk"]
    Fetch --> Render["Render Chart Component"]

Configuring defineAsyncComponent Options

  • loader: A factory function returning a dynamic import promise: () => import('./HeavyChart.vue').
  • loadingComponent: A lightweight spinner or skeleton displayed while the chunk downloads.
  • errorComponent: A fallback UI rendered if the network request fails or times out.
  • delay: Milliseconds to wait before showing loadingComponent (default 200ms) to prevent quick flashes.
  • timeout: Maximum milliseconds before showing errorComponent.

Practical SFC Async Component Example

Here, HeavyChart is not downloaded when the page opens. Clicking the button sets showChart to true, which triggers the lazy network import inside <script setup>.

<script setup>
import { ref, defineAsyncComponent } from 'vue';
import LoadingSpinner from './components/LoadingSpinner.vue';
import ErrorNotice from './components/ErrorNotice.vue';

const HeavyChart = defineAsyncComponent({
  loader: () => import('./components/HeavyChart.vue'),
  loadingComponent: LoadingSpinner,
  errorComponent: ErrorNotice,
  delay: 200,
  timeout: 5000
});

const showChart = ref(false);
</script>

<template>
  <section class="analytics-page">
    <h2>Performance Overview</h2>
    <button @click="showChart = !showChart">
      {{ showChart ? 'Hide Chart' : 'Load Analytics Chart' }}
    </button>

    <HeavyChart v-if="showChart" />
  </section>
</template>

Common Mistakes

  • Passing a Promise Instead of a Factory Function: Writing defineAsyncComponent(import('./Comp.vue')) starts loading immediately on startup. Always wrap it in an arrow function: () => import('./Comp.vue').
  • Splitting Tiny Components: Wrapping small buttons or icons in defineAsyncComponent() adds extra HTTP requests that hurt speed. Reserve async loading for large modules or conditional modals.
  • Using defineAsyncComponent for Route Pages: Vue Router already supports lazy routes natively via component: () => import('./views/AboutView.vue'). Do not wrap route components inside defineAsyncComponent.

Frequently Asked Questions

How does Vite handle defineAsyncComponent() during production builds?

Vite detects the dynamic import() inside loader and automatically creates a separate JavaScript chunk file that browsers fetch only when the component renders.

Can I use defineAsyncComponent together with <Suspense>?

Yes. Async components work with <Suspense> automatically by default. If you want an async component to manage its own loadingComponent instead, set suspensible: false in its options.

Can I register an async component globally?

Yes. Pass the result of defineAsyncComponent(() => import('./MyModal.vue')) to app.component('MyModal', AsyncModal) in main.js.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Related Developer Tools & Topic Hub

Vue Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format HTML templates
CSS Formatter
Clean and format stylesheets
All Vue Articles
Deep-dive guides, tips & discussions
PreviousVue Dynamic Components
Continue JourneyNext: Composition API Intro

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum