Vue.js / Nuxt.js

Vue Performance

Virtual DOM, reactivity optimization, v-once, v-memo, lazy loading, code splitting, bundle size

22 interview questions·
Senior
1

What is the Virtual DOM in Vue?

Answer

The Virtual DOM is a lightweight JavaScript representation of the real DOM tree. Vue uses the Virtual DOM to minimize direct DOM manipulations, which are expensive in terms of performance. When state changes, Vue creates a new Virtual DOM, compares it with the old one (diffing algorithm), then applies only the necessary changes to the real DOM. This approach significantly reduces the number of DOM operations and improves performance, especially for complex applications with many updates.

2

What is the main difference between ref() and shallowRef()?

Answer

ref() creates a deeply reactive reference where all nested properties are also reactive, while shallowRef() only makes the .value property itself reactive. With shallowRef(), deep mutations within the object do not trigger updates. The entire .value must be replaced to trigger reactivity. shallowRef() is useful for optimizing performance with large data structures where deep reactivity is not needed, or for integrating external state systems.

3

What is the role of the v-once directive?

Answer

The v-once directive renders an element and its children only once during the first render, then treats them as static content for all subsequent renders. This means that even if the data changes, the element will never be updated. This directive is useful for optimizing performance of static content that never changes after initial mount, such as banner images, logos, or text that requires no dynamic updates.

4

How does the v-memo directive introduced in Vue 3.2+ work?

5

What is the purpose of markRaw() in Vue?

+19 interview questions

Master Vue.js / Nuxt.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free