A pjax middleware for Laravel 5
Latest commit 536ceb6 Jan 2, 2017 @christophrumpel christophrumpel committed with freekmurze Update LICENSE.md (#16)
Update year of the license


A pjax middleware for Laravel 5

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score Total Downloads

Pjax is 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 certain parts of the page.

The package provides a middleware that can return the response that the jquery plugin expects.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.


You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page 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 = [


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.

Laravel cache busting tip

When using Laravel Elixir to manage your frontend cache busting, you can use it to your advantage to bust pjax's cache. Simply include the elixir method as the content of the x-pjax-version meta tag:

<meta http-equiv="x-pjax-version" content="{{ elixir('css/app.css') }}">

Multiple files:

<meta http-equiv="x-pjax-version" content="{{ elixir('css/app.css') . elixir('css/app2.css') }}">

This way, anytime your frontend's cache gets busted, pjax's cache gets automatically busted as well!

Change log

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.


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.

About Spatie

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.


The MIT License (MIT). Please see License File for more information.