SSR (Server-Side Rendering) generates the full HTML on the server and sends it to the browser, so users see content immediately. CSR (Client-Side Rendering) sends minimal HTML and relies on JavaScript running in the browser to build the page, causing a delay before content appears.
Hydration is the process where Vue takes the server-rendered HTML and attaches event listeners and reactive behavior so the page becomes interactive without rebuilding the whole DOM.
SSR fetches data on the server and includes it in the HTML sent to the client, so the page is ready with data immediately. CSR fetches data only after the JavaScript runs in the browser, causing a delay before data appears.
export default { setup() { if (typeof window === 'undefined') { console.log('Running on server') } } }
On the server, the window object does not exist, so typeof window === 'undefined' is true only during SSR.
onMounted runs after the component is mounted to the DOM, which only happens in the browser. SSR does not mount components to a DOM, so onMounted never runs during SSR.