In this episode, we dive into server-side rendering (SSR) in our Laravel application set up with Laravel Breeze and Vite. We start off by explaining what SSR actually does: instead of just rendering everything on the client (in the browser), SSR lets us pre-render our pages on the server. This is helpful for things like SEO and faster perceived load times, because the HTML is already there for search engines and users when they first load the page.
We take a look at how things appear differently in the browser and when you view the page source, emphasizing that not everything rendered client-side shows up for crawlers. Then, we check out the different entry points in the project—app.js
for the client, and ssr.js
for the server. We look into how SSR builds work by running npm run build
and how to actually start the SSR server.
Of course, things never go 100% smoothly the first time: we get some classic SSR errors, like trying to access the window
object on the server, or using components that just aren't compatible with SSR. You'll see how we debug these, isolate client-only features, and (most importantly) tell Vite to exclude certain packages from SSR with the ssr.noExternal
flag.
The main takeaway is how to recognize and solve SSR compatibility issues—some parts of the app are totally fine being client-side only, and for the rest, we tweak our build configuration to make everything play nice together. By the end, our SSR setup runs without errors, giving us a solid SSR foundation for our Laravel app.