Laravel Starter Kits
If you are using Laravel Starter Kits, Inertia SSR is supported through a build command:Vite Plugin Setup
The recommended way to configure SSR is with the@inertiajs/vite plugin. This approach handles SSR configuration automatically, including development mode SSR without a separate Node.js server.
Configure Vite
Add the Inertia plugin to your You may also configure SSR options explicitly.You may pass
vite.config.js file. The plugin will automatically detect your SSR entry point.vite.config.js
vite.config.js
false to opt out of the plugin’s automatic SSR handling, for example if you prefer to configure SSR manually but still want to use the other features of the Vite plugin.vite.config.js
Development Mode
The Vite plugin handles SSR automatically during development. There is no need to build your SSR bundle or start a separate Node.js server. Simply run your Vite dev server as usual:Production
For production, build both bundles and start the SSR server.Clustering
By default, the SSR server runs on a single thread. You may enable clustering to start multiple Node servers on the same port, with requests handled by each thread in a round-robin fashion.vite.config.js
Manual Setup
The Vite plugin reuses yourapp.js entry point for SSR by default, so no separate file is needed. Most customizations may be handled using the withApp callback.
For more control, such as providing a manual setup callback, you may create a separate resources/js/ssr.js entry point and update your app.js to use client-side hydration.
SSR Entry Point
app.js file that makes sense to run in SSR mode, such as plugins or custom mixins.
Client-Side Hydration
Opting Out of the Vite Plugin
You may passssr: false to the Inertia plugin to disable its automatic SSR handling and manage the SSR build yourself. You should also add the ssr property to the Laravel Vite plugin configuration so it knows about your entry point.
Clustering
You may pass thecluster option to createServer to start multiple Node servers on the same port, with requests handled by each thread in a round-robin fashion.
Running the SSR Server
The SSR server is only required in production. During development, the Vite plugin handles SSR automatically.
--runtime option to specify which runtime you want to use. This allows you to switch from the default Node.js runtime to Bun.
Error Handling
When SSR rendering fails, Inertia gracefully falls back to client-side rendering. The Vite plugin logs detailed error information to the console, including the component name, request URL, source location, and a tailored hint to help you resolve the issue. Common SSR errors are automatically classified. Browser API errors (such as referencingwindow or document in server-rendered code) include guidance on moving the code to a lifecycle hook. Component resolution errors suggest checking file paths and casing.
Inertia also dispatches an SsrRenderFailed event on the server. You may listen for this event to log failures or send them to an error tracking service.
Throwing on Error
Since Inertia gracefully falls back to client-side rendering, SSR failures may go unnoticed. Your tests pass because the client-side render succeeds, but your users never receive server-rendered HTML. This is especially common in E2E tests with tools like Laravel Dusk or Pest Browser Testing. You may set thethrow_on_error option in your config/inertia.php file to throw an exception instead of falling back silently, allowing you to catch SSR issues early.
phpunit.xml to enable this only during testing.
Excluding Pages From SSR
Sometimes you may wish to disable server-side rendering for certain pages or routes in your application.Per-Route via Middleware
You may use the$withoutSsr property on your Inertia middleware to disable SSR for specific route patterns.
Via Facade
You may also disable SSR for specific routes using theInertia::withoutSsr() method, typically called from a service provider.
Per-Request
You may disable SSR for the current request by setting theinertia.ssr.enabled configuration value to false.
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.
inertia:check-ssr Artisan command to verify that the SSR server is running. This can be helpful after deployment and works well as a Docker health check to ensure the server is responding as expected.
inertia.ssr.ensure_bundle_exists configuration value to false.