spatie/laravel-pjax
Laravel middleware that detects PJAX (X-PJAX) requests and returns only the expected HTML fragments instead of full pages, enabling faster navigation with jquery-pjax. Simple composer install and add FilterIfPjax to your HTTP kernel.
@yield sections or dynamic partials).<div id="pjax-container">) and potential adjustments to Blade templates to isolate dynamic content.ResponseCache middleware conflicts).composer require spatie/laravel-pjax.app/Http/Kernel.php.protected $middlewareGroups = [
'web' => [
// ...
\Spatie\Pjax\Middleware\HandlePjaxRequests::class,
],
];
<div id="pjax-container">
@yield('pjax-content')
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.pjax/2.0.1/jquery.pjax.min.js"></script>
$(document).pjax('a[data-pjax]', '#pjax-container');
ResponseCache middleware (disable for PJAX routes).laravel-debugbar, spatie/laravel-activitylog).ResponseCache for non-sensitive data).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| PJAX middleware misconfigured | Broken routes, 500 errors | Test middleware in isolation; use route groups to exclude non-PJAX routes. |
| jQuery/PJAX plugin conflicts | JS errors, no partial updates | Use Vue-PJAX adapter; test in staging with all frontend dependencies. |
| Fragment rendering issues | Incorrect DOM updates | Validate Blade templates return expected fragments; use @debug directives. |
| SEO/SSR degradation | Poor crawl |
How can I help you explore Laravel packages today?