Package Data | |
---|---|
Maintainer Username: | spatie |
Maintainer Contact: | freek@spatie.be (Freek Van der Herten) |
Package Create Date: | 2015-10-16 |
Package Last Update: | 2024-03-08 |
Home Page: | https://freek.dev/293-a-pjax-middleware-for-laravel-5 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:01:49 |
Package Statistics | |
---|---|
Total Downloads: | 321,789 |
Monthly Downloads: | 2,489 |
Daily Downloads: | 72 |
Total Stars: | 510 |
Total Watchers: | 16 |
Total Forks: | 50 |
Total Open Issues: | 0 |
Pjax is a jQuery plugin that leverages ajax to speed up the loading time of your pages. It works by only fetching specific html fragments from the server, and client-side updating only happens on certain parts of the page.
The package provides a middleware that can return the response that the jQuery plugin expects.
There's a Vue-PJAX Adapter equivalent by @barnabaskecskes which doesn't require jQuery.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
You can install the package via composer:
$ composer require spatie/laravel-pjax
Next you must add the \Spatie\Pjax\Middleware\FilterIfPjax
-middleware to the kernel.
// app/Http/Kernel.php
...
protected $middleware = [
...
\Spatie\Pjax\Middleware\FilterIfPjax::class,
];
The provided middleware provides the behaviour that the pjax plugin expects of the server:
An X-PJAX request header is set to differentiate a pjax request from normal XHR requests. In this case, if the request is pjax, we skip the layout html and just render the inner contents of the container.
When using Laravel Mix to manage your frontend cache busting, you can use it to your advantage to bust pjax's cache. Simply include the mix
method as the content of the x-pjax-version
meta tag:
<meta http-equiv="x-pjax-version" content="{{ mix('/css/app.css') }}">
Multiple files:
<meta http-equiv="x-pjax-version" content="{{ mix('/css/app.css') . mix('/css/app2.css') }}">
This way, anytime your frontend's cache gets busted, pjax's cache gets automatically busted as well!
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
The middleware in this package was originally written by Jeffrey Way for the Laracasts-lesson on pjax. His original code can be found in this repo on GitHub.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
The MIT License (MIT). Please see License File for more information.