Skip to main content
Server-side rendering pre-renders your JavaScript pages on the server, allowing your visitors to receive fully rendered HTML when they visit your application. Since fully rendered HTML is served by your application, it’s also easier for search engines to index your site. Server-side rendering uses Node.js to render your pages in a background process; therefore, Node must be available on your server for server-side rendering to function properly. Inertia’s SSR server requires Node.js 22 or higher.

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.
1

Install the Vite plugin

2

Configure Vite

Add the Inertia plugin to your vite.config.js file. The plugin will automatically detect your SSR entry point.
vite.config.js
You may also configure SSR options explicitly.
vite.config.js
You may pass false to opt out of the plugin’s automatic SSR handling, for example if you prefer to configure SSR manually or disable SSR entirely.
vite.config.js
3

Update your build script

Update the build script in your package.json to build both bundles.
package.json

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:
The Vite plugin exposes a server endpoint that Laravel uses for rendering, complete with HMR support.

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

Host

By default, the SSR server binds to 0.0.0.0, making it accessible on all network interfaces. You may restrict it to a specific interface using the host option.
vite.config.js

Manual Setup

The Vite plugin reuses your app.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

Be sure to add anything that’s missing from your 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 pass ssr: 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 the cluster option to createServer to start multiple Node servers on the same port, with requests handled by each thread in a round-robin fashion.

Host

By default, the SSR server binds to 0.0.0.0, making it accessible on all network interfaces. You may pass the host option to createServer to restrict it to a specific interface.

Running the SSR Server

The SSR server is only required in production. During development, the Vite plugin handles SSR automatically.
Once you have built both your client-side and server-side bundles, you may start the SSR server.
With the server running, you should be able to access your app in the browser with server-side rendering enabled. In fact, you should be able to disable JavaScript entirely and still navigate around your application.

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 referencing window or document in server-rendered code) include guidance on moving the code to a lifecycle hook. Components that depend on browser APIs may also be wrapped in WhenMounted. Component resolution errors suggest checking file paths and casing.

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.

Configuring the SSR Request

Disabling SSR

SSR has two layers: the Vite plugin serves SSR during development and builds the SSR bundle for production, while the Laravel adapter dispatches rendering requests to the SSR server. To fully disable SSR, you should disable both.
vite.config.js

Excluding Routes from SSR

Sometimes you may wish to skip server-side rendering for certain routes while keeping SSR enabled for the rest of your application.

Per-Request

You may disable SSR for a single page or request.

Via Middleware

In Laravel PHP, you may use the $withoutSsr property on your Inertia middleware to disable SSR for specific route patterns.
Laravel PHP

Via Facade

In Laravel PHP, you may also exclude specific routes using the Inertia::withoutSsr() method, typically called from a service provider.
Laravel PHP

Client-Only Components

v3.8.0+ Sometimes, a component relies on browser APIs such as window or document and cannot be rendered on the server. Instead of disabling SSR for the entire page, you may wrap the component in WhenMounted, which renders its children only after mounting in the browser. The fallback is rendered on the server and during hydration instead.
The fallback only appears on the initial server-rendered page load. Subsequent visits, as well as applications not using SSR, render the children immediately. Note that WhenMounted only skips rendering on the server. The wrapped component is still part of your SSR bundle, so its module must be safe to import on the server.

Deployment

When deploying your SSR-enabled app to production, you’ll need to build both the client-side and server-side bundles, and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.

Laravel Cloud

To run the SSR server on Laravel Cloud, you may use Cloud’s native support for Inertia SSR.

Laravel Forge

To run the SSR server on Forge, you may enable it via the Inertia SSR toggle in your site’s application panel. Forge will create the required daemon and, optionally, update your deploy script to restart the SSR server on each deployment.