0
0
Vueframework~20 mins

Lazy loading routes in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Lazy Loading Routes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a route is lazy loaded in Vue?

Consider a Vue app using lazy loading for routes. What is the main effect on the app's behavior?

AThe route's component is loaded immediately when the app starts, increasing initial load time.
BThe route's component is loaded only when the user navigates to that route, reducing initial load time.
CThe route's component is never loaded unless manually imported elsewhere in the app.
DThe route's component is loaded multiple times every time the route is visited.
Attempts:
2 left
💡 Hint

Think about how lazy loading helps with app performance by delaying loading.

📝 Syntax
intermediate
2:00remaining
Which Vue router syntax correctly lazy loads a route component?

Given Vue Router, which option correctly lazy loads the About component?

Vue
const routes = [
  {
    path: '/about',
    component: /* ??? */
  }
];
Acomponent: () => require('./components/About.vue')
Bcomponent: import('./components/About.vue')
Ccomponent: require('./components/About.vue')
Dcomponent: () => import('./components/About.vue')
Attempts:
2 left
💡 Hint

Lazy loading uses a function that returns a dynamic import promise.

🔧 Debug
advanced
2:00remaining
Why does this lazy loaded route cause a runtime error?

Look at this route definition:

const routes = [{ path: '/home', component: import('./Home.vue') }];

What error will occur and why?

ATypeError because component expects a function returning a Promise, but got a Promise directly.
BSyntaxError because import cannot be used inside an object literal.
CReferenceError because './Home.vue' does not exist.
DNo error; the route will lazy load correctly.
Attempts:
2 left
💡 Hint

Check what the component property expects for lazy loading.

state_output
advanced
2:00remaining
What is the effect on bundle size when using lazy loading for routes?

In a Vue app, if you lazy load the Profile route component, what happens to the app's initial JavaScript bundle size?

AThe initial bundle size decreases because the Profile component code is split into a separate chunk.
BThe initial bundle size increases because lazy loading adds extra code to manage chunks.
CThe initial bundle size stays the same because all components are bundled together anyway.
DThe initial bundle size becomes zero because no components are loaded initially.
Attempts:
2 left
💡 Hint

Think about how code splitting affects the main bundle.

🧠 Conceptual
expert
3:00remaining
Why might you combine lazy loading with route prefetching in Vue?

Lazy loading delays loading a route's component until navigation. Prefetching loads it earlier. Why combine both?

ATo prevent any component from ever loading unless manually triggered.
BTo increase initial load time by loading all components upfront.
CTo improve user experience by loading components just before navigation without increasing initial load time.
DTo disable lazy loading and always load components synchronously.
Attempts:
2 left
💡 Hint

Consider balancing fast startup and smooth navigation.