Skip to content

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.

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

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 active Inertia module instance
  • $pageObject: the serialized Inertia v3 Page Object array
  • $locale: resolved language code (when inertiaViewData() supplies it)
  • $head: combined <head> tags from inertiaViewData()['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.

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
}

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:

  1. A visitor with an older tab clicks an Inertia link carrying the previous X-Inertia-Version header.
  2. ProcessWire detects the mismatch on GET requests and responds with 409 Conflict plus X-Inertia-Location: <current-url>.
  3. 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.

ProcessWire’s template pipeline often uses $config->prependTemplateFile = '_init.php' and $config->appendTemplateFile = '_main.php'.

  • By default, disableAppendTemplateFile is enabled (true). Inertia sets $template->noAppendTemplateFile = true on enabled templates so _main.php does not wrap your Inertia output, while leaving classic templates untouched.
  • By default, disablePrependTemplateFile is disabled (false), so shared variables and $inertia->share() calls inside site/templates/_init.php continue to run before your template controller.

Next steps