# Pjax [![Build Status](http://img.shields.io/travis/MoOx/pjax.svg)](https://travis-ci.org/MoOx/pjax). > Easily enable fast AJAX navigation on any website (using pushState + XHR) Pjax is ~~a jQuery plugin~~ **a standalone JavaScript module** that uses AJAX (XmlHttpRequest) and [pushState()](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history) to deliver a fast browsing experience. _It allows you to completely transform the user experience of standard websites (server side generated or static ones) to make them feel like they are browsing an app, especially for users with low bandwidth connection._ **No more full page reloads. No more multiple HTTP requests.** ## Demo [You can see this running on my website](http://moox.io), with sexy CSS animations when switching pages. ## Installation - You can install pjax from **npm**: ```shell npm install pjax ``` - You can also link directly to the [bundle](https://cdn.jsdelivr.net/npm/pjax/pjax.js): ```html ``` Or the [minified bundle](https://cdn.jsdelivr.net/npm/pjax/pjax.min.js): ```html ``` ## No dependencies _There is nothing you need. No jQuery or anything else._ ## How Pjax works Pjax loads pages using AJAX & updates the browser's current url using pushState without reloading your page's layout or any resources (JS, CSS), giving a fast page load. _But under the hood, it's just ONE HTTP request with a pushState() call._ Obviously, for [browsers that don't support pushState()](http://caniuse.com/#search=pushstate) Pjax gracefully degrades and does not do anything at all. It simply works with all permalinks & can update all parts of the page you want (including HTML metas, title, and navigation state). - It's not limited to one container, like jQuery-Pjax is. - It fully supports browser history (back & forward buttons). - It supports keyboard browsing. - Automatically falls back to classic navigation for external pages (thanks to Capitain Obvious's help). - Automatically falls back to classic navigation for internal pages that do not have an appropriate DOM tree. - You can add pretty cool CSS transitions (animations) very easily. - It's around 4kb (minified & gzipped). ### Under the hood - It listens to every click on links _you want_ (by default all of them). - When an internal link is clicked, Pjax grabs HTML from your server via AJAX. - Pjax renders the page's DOM tree (without loading any resources - images, CSS, JS...). - It checks that all defined parts can be replaced: - if the page doesn't meet the requirements, classic navigation is used. - if page meets the requirements, Pjax does all defined DOM replacements. - Then, it updates the browser's current URL using pushState. ## Overview Pjax is fully automatic. You don't need to setup anything in the existing HTML. You just need to designate some elements on your page that will be replaced when you navigate your site. Consider the following page. ```html
Sha blah blah.
``` We want Pjax to intercept the URL `/blah`, and replace `.my-Content` with the results of the request. Oh and the `