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.
Enabling Server-Side Rendering
Section titled “Enabling Server-Side Rendering”-
Build your SSR bundle with Vite
Configure your Vite build to output an SSR bundle inside
site/(for examplesite/templates/assets/dist/ssr/ssr.mjs). -
Configure SSR settings under Modules > Configure > Inertia
- Enable Server-Side Rendering (
ssrEnabled): check to enable. - SSR Server URL (
ssrUrl): defaults tohttp://127.0.0.1:13714/render. Must pass the loopback or allowlist policy enforced byHttpGateway::isSafeSsrUrl(). - SSR Timeout (
ssrTimeout): defaults to1.5seconds.
- Enable Server-Side Rendering (
-
Start and verify the SSR server
Terminal window # Start with Node (default) or Bunphp vendor/bin/wire inertia:ssr start --runtime=node --bundle=site/templates/assets/dist/ssr/ssr.mjs# Check health statusphp vendor/bin/wire inertia:ssr status --json
Managing the SSR Process (inertia:ssr)
Section titled “Managing the SSR Process (inertia:ssr)”Use vendor/bin/wire inertia:ssr for local development, health checks, and deployment scripts:
# Check whether the SSR gateway is reachable and healthyphp vendor/bin/wire inertia:ssr status
# Start using Bun runtime instead of Nodephp vendor/bin/wire inertia:ssr start --runtime=bun
# Preview the planned action without starting or stopping processesphp vendor/bin/wire inertia:ssr start --dry-run
# Stop the running SSR server without interactive promptsphp vendor/bin/wire inertia:ssr stop --force --jsonFault-Tolerant CSR Fallback
Section titled “Fault-Tolerant CSR Fallback”If the SSR server crashes, is restarting during a deployment, or exceeds ssrTimeout:
HttpGatewaycatches the connection or timeout failure silently without throwing a 500 error.- ProcessWire renders
_inertia.phpwith an empty<div id="app"></div>and the embedded<script type="application/json" data-page="app">payload. - 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.
Performance Best Practices
Section titled “Performance Best Practices”- 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_timeand automaticWireCacheinvalidation onPages::saved,Pages::trashed, andPages::deleted. - Use partial reloads (
only/except): Request only the changed prop slices when updating filters or pagination (router.reload({ only: ['articles'] })). - Keep
OptionalProplazy: Place modal-only or tab-only data inside$inertia->optional(fn(): array => ...)so it is never evaluated during normal navigation.