Skip to content

SSR & Performance

Inertia supports Server-Side Rendering (SSR) out of the box through Totoglu\Inertia\Ssr\HttpGateway. On initial full-page loads, ProcessWire posts the serialized Page Object to your local Node or Bun SSR server, injects the returned <head> tags and body markup into _inertia.php, and falls back automatically to client-side rendering (CSR) if the SSR server is stopped or times out.

  1. Build your SSR bundle with Vite

    Configure your Vite build to output an SSR bundle inside site/ (for example site/templates/assets/dist/ssr/ssr.mjs).

  2. Configure SSR settings under Modules > Configure > Inertia

    • Enable Server-Side Rendering (ssrEnabled): check to enable.
    • SSR Server URL (ssrUrl): defaults to http://127.0.0.1:13714/render. Must pass the loopback or allowlist policy enforced by HttpGateway::isSafeSsrUrl().
    • SSR Timeout (ssrTimeout): defaults to 1.5 seconds.
  3. Start and verify the SSR server

    Terminal window
    # Start with Node (default) or Bun
    php vendor/bin/wire inertia:ssr start --runtime=node --bundle=site/templates/assets/dist/ssr/ssr.mjs
    # Check health status
    php vendor/bin/wire inertia:ssr status --json

Use vendor/bin/wire inertia:ssr for local development, health checks, and deployment scripts:

Terminal window
# Check whether the SSR gateway is reachable and healthy
php vendor/bin/wire inertia:ssr status
# Start using Bun runtime instead of Node
php vendor/bin/wire inertia:ssr start --runtime=bun
# Preview the planned action without starting or stopping processes
php vendor/bin/wire inertia:ssr start --dry-run
# Stop the running SSR server without interactive prompts
php vendor/bin/wire inertia:ssr stop --force --json

If the SSR server crashes, is restarting during a deployment, or exceeds ssrTimeout:

  1. HttpGateway catches the connection or timeout failure silently without throwing a 500 error.
  2. ProcessWire renders _inertia.php with an empty <div id="app"></div> and the embedded <script type="application/json" data-page="app"> payload.
  3. The browser hydrates normally on the client so visitors never see a broken page.

Combining SSR <head> With inertiaViewData()

Section titled “Combining SSR <head> With inertiaViewData()”

In _inertia.php, printing <?= $head ?? '' ?> automatically combines the server-side tags returned by your Custom Page Class inertiaViewData()['head'] with any <Head> tags rendered by the SSR server.

  • Defer secondary queries: Wrap recommendations, analytics counts, and heavy aggregations in $inertia->defer(fn(): array => ...) so the initial HTML response returns immediately.
  • Cache shared reference data with OnceProp: Use $inertia->shareOnce('navigation', ...)->as('site_navigation')->until(3600) or omit ->until() to inherit $template->cache_time and automatic WireCache invalidation on Pages::saved, Pages::trashed, and Pages::deleted.
  • Use partial reloads (only / except): Request only the changed prop slices when updating filters or pagination (router.reload({ only: ['articles'] })).
  • Keep OptionalProp lazy: Place modal-only or tab-only data inside $inertia->optional(fn(): array => ...) so it is never evaluated during normal navigation.

Next steps