Code Monkey home page Code Monkey logo

laravel-pjax's Introduction

laravel-pjax

laravel-pjax is a pjax middleware for Laravel >5.1.

By adding pjax & jQuery to your web application, ajax and pushState can be used to deliver a fast browsing experience with real permalinks, page titles, and a working back button.

This middleware adds some functionality that other middleware (at the time of writing) did not provide, such as container whitelists and faster page filtering.

I wanted to have some additional functionality for loading "pjax" AJAX requests, so I quickly threw together this package.

Setting up the middleware

Install the package:

# composer require timgws/laravel-pjax

Add the middleware to your app's kernel configuration. The higher the better!

// app/Http/Kernel.php

// ...
protected $middleware = [
    // ...
    \timgws\pjax\Middleware::class,
];

Add the service provider:

// config/app.php

// ...
    'providers' => [
        // ... Laravel providers

        timgws\pjax\ServiceProvider::class,

        // ... app providers ...
    ],

Publish the config file:

php artisan vendor:publish --provider="timgws\pjax\ServiceProvider" --tag="config"

and test!

Limiting containers that can be requested

One major difference between this module and other Laravel pjax middleware is that you can limit which containers can be requested via HTTP headers.

You may wish to edit the pjax.php config file to limit valid_containers

return [
    'valid_containers' => [
        '#pjax-container', '.content'
    ]
];

See https://github.com/defunkt/jquery-pjax#usage for further information.

Force reload of page when version changes

Inside config.php, set the layout version to force a hard reload of the requested page when a client is on an old version of the layout.

Bumping the version will force clients to do a full reload the next request getting the new layout and assets

Set the version to something like 'v1'. Also, you will need to add a meta tag like this to the base layout:

      <meta http-equiv="x-pjax-version" content="v1">
      return [
          'layout_version' => 'v1'
      ];

See https://github.com/defunkt/jquery-pjax#usage for further information.

Contributors

Contributors on GitHub

License

TODO

  • Build test suite

laravel-pjax's People

Contributors

timgws avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.