webkulwp/inertia
Composer 安装命令:
composer require webkulwp/inertia
包简介
Inertia.js server-side adapter for PHP. Handles full visits, Inertia XHR visits, asset-version 409 handshakes and partial reloads. Framework-agnostic, with transparent WordPress integration.
关键字:
README 文档
README
Inertia.js server-side adapter for PHP — the equivalent of what
inertia-laravel provides on Laravel, for any plain-PHP application.
It is framework-agnostic: everything runs on native PHP. When WordPress is
loaded, its helpers (wp_json_encode, status_header, sanitize_text_field,
wp_head / wp_footer in the default shell, the blog_charset option, …)
are picked up automatically — no configuration needed.
It handles the full Inertia protocol:
- First / standard visit → full HTML document with the page object embedded
in a JSON script tag (
script[data-page="<id>"][type="application/json"], the Inertia v3 convention). - Inertia visit (XHR with
X-Inertia: true) → bare JSON page object, no HTML, so the client swaps props without a page reload. - Stale assets (
X-Inertia-Versionmismatch on GET) →409+X-Inertia-Location, telling the client to do one hard reload to pick up new bundles. - Partial reloads → prop filtering via
X-Inertia-Partial-Data/X-Inertia-Partial-Except, with closure props resolved lazily after filtering so skipped props cost no queries.
Installation
composer require webkul/inertia
While the package lives inside a project as a path repository, add to the
project's composer.json:
{
"repositories": [
{ "type": "path", "url": "packages/inertia" }
],
"require": {
"webkul/inertia": "@dev"
}
}
Usage
Plain PHP
use Webkul\Inertia\Inertia; $inertia = Inertia::instance() ->set_version( '1.0.0' ) // string or callable, e.g. a build hash ->set_app_id( 'app' ); // container / script id for the default shell $inertia->render( 'Order', array( 'orders' => fn() => fetch_orders(), // lazy: skipped on partial reloads 'filters' => $filters, ) );
WordPress (custom HTML shell)
use Webkul\Inertia\Inertia; $inertia = Inertia::instance() ->set_version( MY_PLUGIN_SCRIPT_VERSION ) ->set_root_view( array( My_Template::instance(), 'render_ui_template' ) ); if ( ! $inertia->is_inertia_request() ) { // Assets are only needed for the HTML shell, not for JSON visits. my_plugin_enqueue_app_assets(); } $inertia->render( 'Order', $props );
render() always terminates the request.
Configuration
| Method | Purpose |
|---|---|
set_version( string|callable $version ) |
Asset version used for the 409 stale-asset handshake. |
set_root_view( callable $renderer ) |
Renderer for the HTML shell on standard visits. Receives ( string $page_json, array $page ) and must output the full document. |
set_app_id( string $id ) |
Container / script id used by the built-in fallback shell (default app). Only relevant when no root view is set. |
set_charset( string $charset ) |
Response charset (default UTF-8). Under WordPress the blog_charset option takes precedence. |
If no root view is configured, a minimal shell is rendered: a JSON script tag
plus an empty <div id="<app id>"> — and, inside WordPress, wp_head() /
wp_footer() / body_class() are included automatically.
Examples
Runnable end-to-end examples live in examples/:
examples/react/— client built with the official@inertiajs/reactadapter (React 18), including SPA links and partial reloads viarouter.reload({ only: [...] }).examples/vanilla-js/— no framework: a ~70 line hand-rolled client showing the raw protocol (boot from the JSON script tag,fetch()visits withX-Inertiaheaders, the 409 hard-reload handshake, partial reloads, back/forward handling).
Each folder is a standalone mini-app: php -S localhost:8000 index.php.
webkulwp/inertia 适用场景与选型建议
webkulwp/inertia 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「wordpress」 「SPA」 「inertia」 「inertiajs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webkulwp/inertia 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webkulwp/inertia 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webkulwp/inertia 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel-Nuxt starter project template.
Appui DOM Interface
A Laravel-Vue SPA starter project template with Tailwind CSS integration.
Alfabank REST API integration
A simple lightweight admin template based on laravel and vuetifyjs. Simple and clean
Build a SPA with Laravel and Nuxt
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-15