← Back to Vue.js Course | Chapter 10: Best Practices | Lesson 3 of 6

Performance tips

Small habits, like using computed values, stable keys and lazy loading, keep Vue apps fast.

In this page:

  1. Performance tips

Performance tips

Prefer computed over methods for derived data, use keys on lists, avoid deep reactivity on huge read-only data with shallowRef, split routes with dynamic imports, and virtualize very long lists.

Use v-once and v-memo for static or rarely changing parts and measure before optimizing.

Note: shallowRef and markRaw avoid making large objects deeply reactive.

Example: Performance tips

markup
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="app"><p>{{ status }}</p></div>
<script>
  Vue.createApp({
    setup() {
      const big = Vue.shallowRef({ items: Array.from({ length: 1000 }, (_, i) => i) });
      const deep = Vue.ref({ items: [1, 2, 3] });
      const status = `shallow keeps ${big.value.items.length} raw items; deepProxy=${Vue.isReactive(deep.value)}, shallowProxy=${Vue.isReactive(big.value)}`;
      console.log(status);
      return { status };
    },
  }).mount("#app");
</script>
</body>
</html>

<!-- Output:
Rendered: shallow keeps 1000 raw items; deepProxy=true, shallowProxy=false
console: shallow keeps 1000 raw items; deepProxy=true, shallowProxy=false
-->
Live Example
Related Topics
Common Mistakes
  1. Deep reactivity on huge data
  2. Heavy work inside templates
  3. Optimizing before measuring
Chapter Summary
  • Use computed for derived data
  • Key lists and virtualize long ones
  • shallowRef for big read-only data
  • Lazy load routes
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.