In this episode, we dive into setting up server-side rendering (SSR) for our Inertia/Vue app (with Laravel in the backend). First, we go over what SSR actually is, and why it's a big deal: stuff like SEO and search engines actually seeing your content, rather than just relying on client-side JavaScript. We check the page source before SSR and see that almost nothing useful (like the page title or meta tags) makes it to the actual HTML that gets served up — not great!
Next, we walk through the steps required to set up SSR in the codebase. We install the necessary server renderer from Vue, make a new ssr.js
entry point (which is mostly a copy of our client code, with a few tweaks like using createSSRApp
instead of createApp
, and removing anything window-related), and wire it all up so both client and server bundles get built. There's a bit of troubleshooting around typical SSR gotchas, like not being able to use window
or other browser-only globals on the server.
We adjust our Vite config to point to our new ssr.js
file, and update our npm scripts to make running both builds a breeze. Then, we run the SSR dev server to actually serve up the server-rendered content, and finally confirm that our page source now includes all the juicy bits for SEO!
We also set up all the Ziggy/Laravel route stuff so it's happy in both client and server environments, and get our titles and meta tags rendering correctly on the server (using the Inertia head
directive in our Blade templates). By the end, everything is working as it should: the page source shows real content, the title, and meta tags — just like we'd expect from a "real" SSR app. This means search engines and crawlers will get all the info they need, improving discoverability of our pages.