Laravel Starter Kits
If you are using Laravel Breeze or Jetstream, you may install the starter kit’s scaffolding with Inertia SSR support pre-configured using the--ssr flag.
Install Dependencies
If you are not using a Laravel starter kit and would like to manually configure SSR, we’ll first install the additional dependencies required for server-side rendering. This is only necessary for the Vue adapters, so you can skip this step if you’re using React or Svelte.Add Server Entry-Point
Next, we’ll create aresources/js/ssr.js file within our Laravel project that will serve as our SSR entry point.
resources/js/app.js file, except it’s not going to run in the browser, but rather in Node.js. Here’s a complete example.
app.js file that makes sense to run in SSR mode, such as plugins or custom mixins.
Setup Vite
Next, we need to update our Vite configuration to build our newssr.js file. We can do this by adding a ssr property to Laravel’s Vite plugin configuration in our vite.config.jsfile.
Update Npm Script
Next, let’s update thebuild script in our package.json file to also build our new ssr.js file.
Running the SSR Server
Now that you have built both your client-side and server-side bundles, you should be able run the Node-based Inertia SSR server using the following command.Client Side Hydration
Deployment
When deploying your SSR enabled app to production, you’ll need to build both the client-side (app.js) and server-side bundles (ssr.js), and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
inertia:stop-ssr Artisan command. Your process monitor (such as Supervisor) should be responsible for automatically restarting the SSR server after it has stopped.
Laravel Forge
To run the SSR server on Forge, you should create a new daemon that runsphp artisan inertia:start-ssr from the root of your app. Or, you may utilize the built-in Inertia integration from your Forge application’s management dashboard.
Next, whenever you deploy your application, you can automatically restart the SSR server by calling the php artisan inertia:stop-ssr command. This will stop the existing SSR server, forcing a new one to be started by your process monitor.
Heroku
To run the SSR server on Heroku, update theweb configuration in your Procfile to run the SSR server before starting your web server.
heroku/nodejs buildpack installed in addition to the heroku/php buildback for the SSR server to run.