Question presented to candidate: "Our Vue storefront is a client-rendered SPA and the marketing team says search engines and slow phones see a blank page first. Walk me through how server-side rendering works in Vue: what happens on the server, what gets sent, and what the browser does with it."
What a strong answer should cover:
- The server runs the same components and turns them into an HTML string with
renderToString(or a stream) fromvue/server-renderer; templates are compiled into string-concatenatingssrRenderfunctions. - Only
setup(),onServerPrefetchand render run on the server.onMountedand other DOM hooks do not, and there is no reactivity-driven re-render. - The browser receives real markup (fast first paint, crawlable), plus the JS bundle and serialised state.
- Hydration:
createSSRApp(...).mount()walks the existing DOM, attaches event listeners and adopts the nodes instead of re-creating them;createAppwould throw the markup away. - The app factory pattern (fresh app and store per request) to avoid cross-request state pollution.
- Costs: server CPU, a Node runtime to host, code that must not touch
windowduring setup, and hydration mismatches.
Clarifying questions expected:
- "Is the content per-user, or could some pages be prerendered at build time instead?"
- "Do we want to own the server setup, or use a framework such as Nuxt?"
Code / implementation expected: Optional β a minimal server that calls renderToString plus a client entry that hydrates with createSSRApp.