100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
JavaScript

Lazy Loading and Code Splitting

Covers how to split a Vue application into smaller chunks using dynamic imports for routes and components, reducing initial bundle size and improving load performance.

Performance & ProductionIntermediate9 min readJul 9, 2026
Analogies

Lazy Loading and Code Splitting

As a Vue application grows, bundling every component, route, and library into a single JavaScript file means users pay the download and parse cost for the entire application before they can interact with even the first screen. Code splitting solves this by breaking the bundle into smaller chunks that are loaded on demand, typically driven by dynamic import() calls that the build tool (Vite or webpack) automatically recognizes as split points. Lazy loading is the runtime behavior that results: instead of eagerly importing a component or route module at startup, the browser fetches it only when it is actually needed, such as when the user navigates to a specific route.

🏏

Cricket analogy: Packing every player's full career stats booklet into one heavy program before a fan can even see today's scorecard is wasteful — code splitting is like handing out only today's team sheet first, fetching Sachin Tendulkar's full career archive only if the fan taps his name.

Route-level code splitting with Vue Router

The most impactful place to apply code splitting in a typical Vue app is at the route level, since users rarely visit every route in a single session. Vue Router supports this natively: instead of importing a route's component eagerly at the top of the router configuration file, you pass a function that returns a dynamic import(). The router then only fetches that chunk when the user actually navigates to the matching path, keeping the initial bundle limited to the shell of the application plus whatever route is loaded first.

🏏

Cricket analogy: A cricket stats app doesn't preload the "Bowling Records" page until a fan actually taps that tab — Vue Router's dynamic import per route is like only printing that section of the scorecard booklet when someone asks to see it.

javascript
// router/index.js
import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'home',
    // Eager: loaded immediately, part of the main bundle
    component: () => import('@/views/HomeView.vue'),
  },
  {
    path: '/reports/:reportId',
    name: 'report-detail',
    // Lazy: its own chunk, fetched only when this route is visited
    component: () => import('@/views/ReportDetailView.vue'),
  },
  {
    path: '/admin',
    name: 'admin',
    component: () => import('@/views/AdminDashboardView.vue'),
  },
]

export const router = createRouter({
  history: createWebHistory(),
  routes,
})

Lazy-loading individual components

Beyond routes, Vue's defineAsyncComponent lets you lazily load any component, which is especially useful for large, rarely-used UI such as modals, rich text editors, charting libraries, or admin-only widgets that would otherwise inflate the bundle for every visitor even if most never open them. defineAsyncComponent also accepts an options object supporting loading and error components, plus a delay and timeout, so you can show a spinner only if the fetch takes noticeably long rather than flashing it on every fast load.

🏏

Cricket analogy: A DRS (Decision Review System) replay overlay only loads its heavy video-analysis code when an umpire actually calls for a review, not on every ball — like defineAsyncComponent lazily loading a rarely-used modal, with a short delay before showing "loading review" so it doesn't flash on quick reviews.

vue
<script setup>
import { defineAsyncComponent } from 'vue'

const ChartWidget = defineAsyncComponent({
  loader: () => import('@/components/ChartWidget.vue'),
  loadingComponent: () => import('@/components/SpinnerIcon.vue'),
  delay: 200,
  timeout: 8000,
})
</script>

<template>
  <section>
    <h2>Monthly Revenue</h2>
    <Suspense>
      <ChartWidget />
      <template #fallback>
        <p>Loading chart</p>
      </template>
    </Suspense>
  </section>
</template>

Under the hood, both () => import(...) in a route definition and defineAsyncComponent rely on the same ES module dynamic import syntax. The build tool statically detects these calls and generates a separate chunk file for each unique import target, then wires up the runtime fetch — no manual bundler configuration is required in a standard Vite-based Vue project.

Over-splitting can backfire: turning every small component into its own chunk multiplies the number of network requests and can make the app feel slower due to request overhead and waterfalls, especially on high-latency connections. Reserve lazy loading for genuinely large, rarely-needed, or route-boundary code, and let the bundler's default chunking handle the rest. It's also worth combining lazy loading with prefetching where it makes sense — for example, prefetching the likely next route's chunk on link hover so the perceived load time on click is minimal, which Vite supports via automatically generated modulepreload hints for statically analyzable dynamic imports.

  • Code splitting breaks a Vue app into smaller chunks loaded on demand instead of one large upfront bundle.
  • Vue Router supports lazy route components natively via component: () => import('...').
  • defineAsyncComponent lazily loads individual components, useful for large or rarely-used UI like modals and charts.
  • Async components can specify loading and error components, plus delay and timeout options.
  • Over-splitting into too many tiny chunks can hurt performance due to request overhead — reserve it for genuinely large or route-level code.
  • Prefetching likely-needed chunks (e.g., on link hover) can hide the latency cost of lazy loading.

Practice what you learned

Was this page helpful?

Topics covered

#JavaScript#VueJsStudyNotes#WebDevelopment#LazyLoadingAndCodeSplitting#Lazy#Loading#Code#Splitting#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse