How It Works
Inertia does not replace ProcessWire’s router or template engine. Instead, it intercepts the output of enabled templates and returns either a full HTML shell on the first visit or a lightweight JSON Page Object on subsequent in-app visits.
Request Lifecycle
Section titled “Request Lifecycle”sequenceDiagram
participant B as Browser (Inertia Client)
participant PW as ProcessWire + Inertia Module
participant SSR as Optional Node/Bun SSR
Note over B,PW: 1. Initial Full-Page Visit
B->>PW: GET /articles/aegean-routes
PW->>PW: Run template & InteractWithInertia
alt SSR Enabled & Healthy
PW->>SSR: POST Page Object JSON
SSR-->>PW: Rendered HTML body & head tags
end
PW-->>B: 200 OK HTML (_inertia.php + JSON payload)
B->>B: Hydrate / Mount React, Vue, or Svelte app
Note over B,PW: 2. Subsequent SPA Visit
B->>PW: GET /articles/bodrum-harbor (X-Inertia: true, X-Inertia-Version: hash)
alt Asset Version Matches
PW-->>B: 200 OK JSON (component, props, url, version)
B->>B: Swap component & update browser history
else Asset Version Changed (New Deploy)
PW-->>B: 409 Conflict (X-Inertia-Location: /articles/bodrum-harbor)
B->>PW: Full browser reload for fresh JS/CSS bundles
end
The Root View (_inertia.php)
Section titled “The Root View (_inertia.php)”On an initial full-page request (when the X-Inertia header is absent), Inertia renders your Root View template (site/templates/_inertia.php by default). The Root View receives:
$inertia: the activeInertiamodule instance$pageObject: the serialized Inertia v3 Page Object array$locale: resolved language code (wheninertiaViewData()supplies it)$head: combined<head>tags frominertiaViewData()['head']and SSR output (if SSR is active)
Calling <?= $inertia->app($pageObject) ?> inside <body> emits the mount element (<div id="app"></div> or SSR markup) together with the Inertia v3 <script type="application/json" data-page="app"> payload tag.
The Inertia v3 Page Object
Section titled “The Inertia v3 Page Object”On XHR visits (X-Inertia: true), ProcessWire skips _inertia.php and returns a JSON payload with Vary: X-Inertia and X-Inertia: true headers:
{ "component": "Articles/Show", "props": { "errors": {}, "csrf": { "name": "TOKEN123", "value": "abc..." }, "flash": { "messages": [], "warnings": [], "errors": [] }, "page": { "id": 1042, "title": "Aegean Routes", "url": "/articles/aegean-routes/" } }, "url": "/articles/aegean-routes/", "version": "f8a1c3d9...", "encryptHistory": false, "clearHistory": false}Automatic Asset Versioning (Vite)
Section titled “Automatic Asset Versioning (Vite)”Because Inertia requires the first-party Vite module, it automatically computes an asset version hash from your Vite build manifest. Whenever you deploy new frontend bundles:
- A visitor with an older tab clicks an Inertia link carrying the previous
X-Inertia-Versionheader. - ProcessWire detects the mismatch on
GETrequests and responds with409 ConflictplusX-Inertia-Location: <current-url>. - The Inertia client performs a clean full-page visit so the visitor receives the updated JavaScript and CSS assets.
You can override the automatic version hash at any time with $inertia->version('custom-release-id') or a closure.
Coexisting With _init.php and _main.php
Section titled “Coexisting With _init.php and _main.php”ProcessWire’s template pipeline often uses $config->prependTemplateFile = '_init.php' and $config->appendTemplateFile = '_main.php'.
- By default,
disableAppendTemplateFileis enabled (true). Inertia sets$template->noAppendTemplateFile = trueon enabled templates so_main.phpdoes not wrap your Inertia output, while leaving classic templates untouched. - By default,
disablePrependTemplateFileis disabled (false), so shared variables and$inertia->share()calls insidesite/templates/_init.phpcontinue to run before your template controller.