Performance: Why SSR matters for Vue
SSR affects how fast the main content appears on screen and improves user interaction speed by pre-rendering HTML on the server.
import { createSSRApp } from 'vue' import { renderToString } from 'vue/server-renderer' export async function render() { const app = createSSRApp(App) return await renderToString(app) }
const app = Vue.createApp(App) app.mount('#app')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-only Vue rendering | Delayed DOM creation until JS runs | Multiple reflows as JS builds DOM | High paint cost due to late DOM | [X] Bad |
| Vue SSR rendering | DOM created from server HTML immediately | Single reflow on initial load | Lower paint cost with ready content | [OK] Good |
createSSRApp is designed for SSR, unlike createApp which is for client-only apps.const app = createSSRApp({
data() { return { message: 'Hello SSR' } },
template: `{{ message }}`
})
// Server renders app to string
const html = await renderToString(app)html contain?const app = createApp({
data() { return { count: 0 } },
template: `{{ count }}
`
})
const html = await renderToString(app)createSSRApp, not createApp.createApp causes renderToString to fail because it expects SSR app instance.createSSRApp on server and sending rendered HTML improves SEO and load speed.Pass the test and this pattern moves unknown