0
0
Vueframework~8 mins

v-once for static content in Vue - Performance & Optimization

Choose your learning style9 modes available
Performance: v-once for static content
MEDIUM IMPACT
This affects the rendering speed by skipping future updates for static parts of the UI, reducing CPU work during re-renders.
Rendering static content inside a Vue component that does not change
Vue
<template>
  <div v-once>
    <h1>{{ title }}</h1> <!-- title never changes -->
  </div>
</template>
<script setup>
const title = 'Welcome to Vue'
</script>
Vue renders the content once and skips it in future updates, reducing CPU and virtual DOM work.
📈 Performance Gainavoids re-render and virtual DOM diff for static nodes
Rendering static content inside a Vue component that does not change
Vue
<template>
  <div>
    <h1>{{ title }}</h1> <!-- title never changes -->
  </div>
</template>
<script setup>
const title = 'Welcome to Vue'
</script>
Vue re-renders the static content on every reactive update, wasting CPU cycles.
📉 Performance Costtriggers re-render and virtual DOM diff on every update
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Without v-onceRe-renders virtual DOM nodes every updateTriggers reflows if DOM changesPaint cost depends on changes[X] Bad
With v-onceRenders DOM nodes once, skips updatesNo reflows from static content on updatesPaint cost only on initial render[OK] Good
Rendering Pipeline
When Vue processes v-once, it renders the element and its children a single time and marks them as static. On subsequent updates, Vue skips these nodes, avoiding the patch and diff steps.
Virtual DOM Diffing
Patch
Re-render
⚠️ BottleneckVirtual DOM diffing and patching for static nodes
Core Web Vital Affected
INP
This affects the rendering speed by skipping future updates for static parts of the UI, reducing CPU work during re-renders.
Optimization Tips
1Use v-once only on truly static content that never changes.
2Avoid v-once on dynamic or interactive elements to prevent stale UI.
3v-once improves interaction responsiveness by skipping unnecessary re-renders.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main benefit of using v-once on static content in Vue?
AIt prevents Vue from re-rendering that content on updates
BIt makes the content editable by the user
CIt forces Vue to always re-render the content
DIt delays rendering until user interaction
DevTools: Performance
How to check: Record a performance profile while interacting with the app. Look for repeated Vue patch operations on static nodes.
What to look for: Reduced number of component re-renders and virtual DOM patches for static content indicates good use of v-once.