{"id":15029344,"url":"https://github.com/moox/pjax","last_synced_at":"2025-05-14T19:08:00.162Z","repository":{"id":15100547,"uuid":"17827281","full_name":"MoOx/pjax","owner":"MoOx","description":"Easily enable fast Ajax navigation on any website (using pushState +  xhr)","archived":false,"fork":false,"pushed_at":"2022-12-07T14:21:04.000Z","size":1062,"stargazers_count":1476,"open_issues_count":54,"forks_count":124,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-05-14T19:07:53.296Z","etag":null,"topics":["ajax","jquery-pjax","navigation","pjax","pjax-request","pushstate"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MoOx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-17T12:32:10.000Z","updated_at":"2025-05-08T02:29:29.000Z","dependencies_parsed_at":"2022-08-08T14:00:34.494Z","dependency_job_id":null,"html_url":"https://github.com/MoOx/pjax","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoOx%2Fpjax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoOx%2Fpjax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoOx%2Fpjax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoOx%2Fpjax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MoOx","download_url":"https://codeload.github.com/MoOx/pjax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ajax","jquery-pjax","navigation","pjax","pjax-request","pushstate"],"created_at":"2024-09-24T20:10:22.001Z","updated_at":"2025-05-14T19:07:59.043Z","avatar_url":"https://github.com/MoOx.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pjax\n\n[![Build Status](https://img.shields.io/travis/MoOx/pjax.svg)](https://travis-ci.org/MoOx/pjax).\n\n\u003e Easily enable fast AJAX navigation on any website (using pushState() + XHR)\n\nPjax is **a standalone JavaScript module** that uses [AJAX](https://developer.mozilla.org/en-US/docs/Web/Guide/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.\n\n_It allows you to completely transform the user experience of standard websites (server-side generated or static ones) to make users feel like they are browsing an app, especially for those with low bandwidth connections._\n\n**No more full page reloads. No more multiple HTTP requests.**\n\n_Pjax does not rely on other libraries, like jQuery or similar. It is written entirely in vanilla JS._\n\n## Installation\n\n- You can link directly to the [bundle](https://cdn.jsdelivr.net/npm/pjax/pjax.js):\n  ```html\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/pjax@VERSION/pjax.js\"\u003e\u003c/script\u003e\n  ```\n\n- Or the [minified bundle](https://cdn.jsdelivr.net/npm/pjax/pjax.min.js):\n  ```html\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/pjax@VERSION/pjax.min.js\"\u003e\u003c/script\u003e\n  ```\n\n- You can also install Pjax from **npm**:\n  ```shell\n  npm install pjax\n  ```\n  **Note**: If you use this option, you will need to do one of the following:\n    - Link a script tag to either `pjax.js` or `pjax.min.js`. E.g.:\n    ```html\n    \u003cscript src=\"./node_modules/pjax/pjax.js\"\u003e\u003c/script\u003e\n    ```\n    - Use a bundler like Webpack. (`index.js` cannot be used in the browser without a bundler).\n\n- Or you can clone the repo and build the bundle from the source using npm:\n  ```shell\n  git clone https://github.com/MoOx/pjax.git\n  cd pjax\n  npm install\n  npm run build\n  ```\n  and then link a script tag to either `pjax.js` or `pjax.min.js`. E.g.:\n  ```html\n  \u003cscript src=\"./pjax.min.js\"\u003e\u003c/script\u003e\n  ```\n\n---\n\n## What Pjax Does\n\n_Under the hood, it's just ONE HTTP request with a `pushState()` call._\n\nPjax loads pages using AJAX and updates the browser's current URL using `pushState()` _without_ reloading your page's layout or any resources (JS, CSS), giving a fast page load.\n\nIt works with all permalinks and can update all the parts of the page you want (including HTML metas, title, and navigation state).\n\nIn the case of [browsers that don't support `history.pushState()`](http://caniuse.com/#search=pushstate), Pjax gracefully degrades and does not do anything at all.\n\nAdditionally, Pjax:\n\n- Is not limited to one container, like jQuery-Pjax is.\n- Fully supports browser history (back and forward buttons).\n- Supports keyboard browsing.\n- Automatically falls back to standard navigation for external pages (thanks to Captain Obvious's help).\n- Automatically falls back to standard navigation for internal pages that do not have an appropriate DOM tree.\n- Allows for CSS transitions (animations) very easily.\n- Is only around 6kb (minified and gzipped).\n\n## How Pjax Works\n\n- It listens to every click on links _you want_ (by default all of them).\n- When an internal link is clicked, Pjax fetches the page's HTML via AJAX.\n- Pjax renders the page's DOM tree (without loading any resources - images, CSS, JS, etc).\n- It checks that all defined parts can be replaced:\n    - If the page doesn't meet the requirements, standard navigation is used.\n    - If the page meets the requirements, Pjax does all defined DOM replacements.\n- Then it updates the browser's current URL using `pushState()`.\n\n## Overview\n\n_Pjax is fully automatic_. You don't need to change anything about your existing HTML,\nyou just need to designate which elements on your page that you want to be replaced when your site is navigated.\n\nConsider the following page.\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003c!-- metas, title, styles, etc --\u003e\n  \u003ctitle\u003eMy Cool Blog\u003c/title\u003e\n  \u003cmeta name=\"description\" content=\"Welcome to My Cool Blog\"\u003e\n  \u003clink href=\"/styles.css\" rel=\"stylesheet\"\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n  \u003cheader class=\"the-header\"\u003e\n    \u003cnav\u003e\n      \u003ca href=\"/\" class=\"is-active\"\u003eHome\u003c/a\u003e\n      \u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\n      \u003ca href=\"/contact\"\u003eContact\u003c/a\u003e\n    \u003c/nav\u003e\n  \u003c/header\u003e\n\n  \u003csection class=\"the-content\"\u003e\n    \u003ch1\u003eMy Cool Blog\u003c/h1\u003e\n    \u003cp\u003e\n      Thanks for stopping by!\n\n      \u003ca href=\"/about\"\u003eClick Here to find out more about me.\u003c/a\u003e\n    \u003c/p\u003e\n  \u003c/section\u003e\n\n  \u003caside class=\"the-sidebar\"\u003e\n    \u003ch3\u003eRecent Posts\u003c/h3\u003e\n    \u003c!-- sidebar content --\u003e\n  \u003c/aside\u003e\n\n  \u003cfooter class=\"the-footer\"\u003e\n    \u0026copy; My Cool Blog\n  \u003c/footer\u003e\n\n  \u003cscript src=\"onDomReadystuff.js\"\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    // analytics\n  \u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nWe want Pjax to intercept the URL `/about`, and replace `.the-content` with the resulting content of the request.\n\nIt would also be nice if we could replace the `\u003cnav\u003e` to show that the `/about` link is active, as well as update our page meta and the `\u003caside\u003e` sidebar.\n\nSo all in all we want to update the page title and meta, header, content area, and sidebar, **without reloading styles or scripts**.\n\nWe can easily do this by telling Pjax to listen on all `a` tags (which is the default) and use CSS selectors defined above (without forgetting minimal meta):\n\n``` javascript\nvar pjax = new Pjax({\n  selectors: [\n    \"title\",\n    \"meta[name=description]\",\n    \".the-header\",\n    \".the-content\",\n    \".the-sidebar\",\n  ]\n})\n```\n\nNow, when someone in a Pjax-compatible browser clicks an internal link on the page, the content of each of the selectors will be replaced with the specific content pieces found in the next page's content.\n\n_Magic! For real!_ **There is no need to do anything server-side!**\n\n## Differences with [jQuery-pjax](https://github.com/defunkt/jquery-pjax)\n\n- No jQuery dependency.\n- Not limited to a container.\n- No server-side requirements.\n- Works for CommonJS environment (Webpack/Browserify), AMD (RequireJS) or even globally.\n- Allows page transitions with CSS animations.\n- Can be easily tweaked, since every method is public (and as a result, overridable).\n\n## Compatibility\n\nPjax only works with [browsers that support the `history.pushState()` API](http://caniuse.com/#search=pushstate). When the API isn't supported, Pjax goes into fallback mode (and it just does nothing).\n\nTo see if Pjax is actually supported by your browser, use `Pjax.isSupported()`.\n\n## Usage\n\n### `new Pjax()`\n\nLet's talk more about the most basic way to get started.\n\nWhen instantiating `Pjax`, you can pass options into the constructor as an object:\n\n```js\nvar pjax = new Pjax({\n  elements: \"a\", // default is \"a[href], form[action]\"\n  selectors: [\"title\", \".the-header\", \".the-content\", \".the-sidebar\"]\n})\n```\n\nThis will enable Pjax on all links, and designate the part to replace using CSS selectors `\"title\", \".the-header\", \".the-content\", \".the-sidebar\"`.\n\nIn some cases, you might want to only target some specific elements to apply Pjax behavior. In that case, you can do two different things:\n\n1. Use a custom CSS selector( such as `\"a.js-Pjax\"` or `\".js-Pjax a\"`, etc).\n2. Override `Pjax.prototype.getElements`.\n    - **Note**: If doing this, make sure to return a `NodeList`.\n\n```js\n// use case 1\nvar pjax = new Pjax({ elements: \"a.js-Pjax\" })\n```\n\n```js\n// use case 2\nPjax.prototype.getElements = function() {\n  return document.getElementsByClassName(\".js-Pjax\")\n}\n\nvar pjax = new Pjax()\n```\n\n### `loadUrl(href, [options])`\n\nWith this method, you can manually trigger the loading of a URL:\n\n```js\nvar pjax = new Pjax()\n\n// use case 1\npjax.loadUrl(\"/your-url\")\n\n// use case 2 (with options override)\npjax.loadUrl(\"/your-other-url\", { timeout: 10 })\n```\n\n### `handleResponse(responseText, request, href, options)`\n\nThis method takes the raw response, processes the URL, then calls `pjax.loadContent()` to actually load it into the DOM.\n\nIt is passed the following arguments:\n\n* **responseText** (string): This is the raw response text. This is equivalent to `request.responseText`.\n* **request** (XMLHttpRequest): This is the XHR object.\n* **href** (string): This is the URL that was passed to `loadUrl()`.\n* **options** (object): This is an object with the options for this request. The structure basically matches the regular options object, with a few extra internal properties.\n\nYou can override this if you want to process the data before, or instead of, it being loaded into the DOM.\n\nFor example, if you want to check for a non-HTML response, you could do the following:\n\n```js\nvar pjax = new Pjax();\n\npjax._handleResponse = pjax.handleResponse;\n\npjax.handleResponse = function(responseText, request, href, options) {\n  if (request.responseText.match(\"\u003chtml\")) {\n    pjax._handleResponse(responseText, request, href, options);\n  } else {\n    // handle non-HTML response here\n  }\n}\n```\n\n### `refresh([el])`\n\nUse this method to bind Pjax to children of a DOM element that didn't exist when Pjax was initialised e.g. content inserted dynamically by another library or script. If called with no arguments, Pjax will parse the entire document again to look for newly-inserted elements.\n\n```js\n// Inside a callback or Promise that runs after new DOM content has been inserted\nvar newContent = document.querySelector(\".new-content\");\n\npjax.refresh(newContent);\n```\n\n\n### `reload()`\n\nA helper shortcut for `window.location.reload()`. Used to force a page reload.\n\n```js\npjax.reload()\n```\n\n## Options\n\n### `elements` (String, default: `\"a[href], form[action]\"`)\n\nCSS selector(s) used to find links to apply Pjax to. If needing multiple specific selectors, separate them by a comma.\n\n```js\n// Single element\nvar pjax = new Pjax({\n  elements: \".ajax\"\n})\n```\n\n```js\n// Multiple elements\nvar pjax = new Pjax({\n  elements: \".pjax, .ajax\",\n})\n```\n\n### `selectors` (Array, default: `[\"title\", \".js-Pjax\"]`)\n\nCSS selectors used to find which content to replace.\n\n```js\nvar pjax = new Pjax({\n  selectors: [\n    \"title\",\n    \"the-content\",\n  ]\n})\n```\n\nIf a query returns multiples items, it will just keep the index.\n\nExample of what you can do:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003ctitle\u003ePage title\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cheader class=\"js-Pjax\"\u003e...\u003c/header\u003e\n  \u003csection class=\"js-Pjax\"\u003e...\u003c/section\u003e\n  \u003cfooter class=\"the-footer\"\u003e...\u003c/footer\u003e\n  \u003cscript\u003e...\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThis example is correct and should work \"as expected\".\n\n**NOTE:** _If the current page and new page do not have the same amount of DOM elements, Pjax will fall back to normal page load._\n\n### `switches` (Object, default: `{}`)\n\nThis is an object containing callbacks that can be used to switch old elements with new elements.\n\nThe object keys should be one of the defined selectors (from the `selectors` option).\n\nExamples:\n\n```js\nvar pjax = new Pjax({\n  selectors: [\"title\", \".Navbar\", \".js-Pjax\"],\n  switches: {\n    \"title\": Pjax.switches.outerHTML, // default behavior\n    \".the-content\": function(oldEl, newEl, options) {\n      // this is identical to the default behavior\n      oldEl.outerHTML = newEl.outerHTML\n      this.onSwitch()\n    },\n    \".js-Pjax\": Pjax.switches.sideBySide\n  }\n})\n```\n\nCallbacks are bound to the Pjax instance itself to allow you to reuse it (ex: `this.onSwitch()`)\n\n### Existing Switch Callbacks\n\n- `Pjax.switches.outerHTML`:\n  The default behavior, replaces elements using `outerHTML`.\n- `Pjax.switches.innerHTML`:\n  Replaces elements using `innerHTML` and copies `className`.\n- `Pjax.switches.replaceNode`:\n  Replaces elements using `replaceChild`\n- `Pjax.switches.sideBySide`:\n  Smart replacing that allows you to have both elements in the same parent when you want to use CSS animations. Old elements are removed when all children have been fully animated (an [animationEnd](http://www.w3.org/TR/css3-animations/#animationend) event is triggered).\n\n### Creating a Switch Callback\n\nYour callback function can do whatever you want, but you need to:\n\n1. Replace the `oldEl`'s content with the `newEl`'s content in some fashion.\n2. Call `this.onSwitch()` to trigger the attached callback.\n\nHere is the default behavior as an example:\n\n```js\nfunction(oldEl, newEl, pjaxOptions) {\n  oldEl.outerHTML = newEl.outerHTML\n  this.onSwitch()\n}\n```\n\n### `switchesOptions` (Object, default: `{}`)\n\nThese are options that can be used during content replacement by switches. For now, only `Pjax.switches.sideBySide` uses it. This is very convenient when you use something like [Animate.css](https://github.com/daneden/animate.css) with or without [WOW.js](https://github.com/matthieua/WOW).\n\n```js\nvar pjax = new Pjax({\n  selectors: [\"title\", \".js-Pjax\"],\n  switches: {\n    \".js-Pjax\": Pjax.switches.sideBySide\n  },\n  switchesOptions: {\n    \".js-Pjax\": {\n      classNames: {\n        // class added to the old element being replaced, e.g. a fade out\n        remove: \"Animated Animated--reverse Animate--fast Animate--noDelay\",\n        // class added to the new element that is replacing the old one, e.g. a fade in\n        add: \"Animated\",\n        // class added on the element when navigating back\n        backward: \"Animate--slideInRight\",\n        // class added on the element when navigating forward (used for new page too)\n        forward: \"Animate--slideInLeft\"\n      },\n      callbacks: {\n        // to make a nice transition with 2 pages at the same time\n        // we are playing with absolute positioning for the element we are removing\n        // \u0026 we need live metrics to have something great\n        // see associated CSS below\n        removeElement: function(el) {\n          el.style.marginLeft = \"-\" + (el.getBoundingClientRect().width/2) + \"px\"\n        }\n      }\n    }\n  }\n})\n```\n\n_Note that `remove` includes `Animated--reverse` which is a simple way to not have to have a duplicate transition (slideIn + reverse =\u003e slideOut)._\n\nHere is some css that works well with the above configuration:\n\n```css\n/*\n  Note: If your content elements don't have a fixed width it can cause\n  an issue when positioning absolutely\n*/\n.js-Pjax { position: relative } /* parent element where switch will be made */\n\n.js-Pjax-child { width: 100% }\n\n/* position for the elements that will be removed */\n.js-Pjax-remove {\n  position: absolute;\n  left: 50%;\n  /* transform: translateX(-50%) */\n  /* transform can't be used since we already use generic translate for the remove effect (eg animate.css) */\n  /* margin-left: -width/2; // made with js */\n  /* you can totally drop the margin-left thing from switchesOptions if you use custom animations */\n}\n\n/* CSS animations */\n.Animated {\n  animation-fill-mode: both;\n  animation-duration: 1s;\n}\n\n.Animated--reverse { animation-direction: reverse }\n\n.Animate--fast { animation-duration: .5s }\n.Animate--noDelay { animation-delay: 0s !important;  }\n\n.Animate--slideInRight { animation-name: Animation-slideInRight }\n\n@keyframes Animation-slideInRight {\n  0% {\n    opacity: 0;\n    transform: translateX(100rem);\n  }\n\n  100% {\n    transform: translateX(0);\n  }\n}\n\n.Animate--slideInLeft { animation-name: Animation-slideInLeft }\n\n@keyframes Animation-slideInLeft {\n  0% {\n    opacity: 0;\n    transform: translateX(-100rem);\n  }\n\n  100% {\n    transform: translateX(0);\n  }\n}\n```\n\nTo give context to this CSS, here is an HTML snippet:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003ctitle\u003ePage Title\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003csection class=\"js-Pjax\"\u003e\n    \u003cdiv class=\"js-Pjax-child\"\u003e\n      Your content here\n    \u003c/div\u003e\n    \u003c!--\n    During the replacement process, you'll have the following tree:\n\n    \u003cdiv class=\"js-Pjax-child js-Pjax-remove Animate...\"\u003e\n      Your OLD content here\n    \u003c/div\u003e\n    \u003cdiv class=\"js-Pjax-child js-Pjax-add Animate...\"\u003e\n      Your NEW content here\n    \u003c/div\u003e\n\n    --\u003e\n  \u003c/section\u003e\n  \u003cscript\u003e...\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### `history` (Boolean, default: `true`)\n\nEnable the use of `pushState()`. Disabling this will prevent Pjax from updating browser history. While possible, there is almost no use case where you would want to do this.\n\nInternally, this option is used when a `popstate` event triggers Pjax (to not `pushState()` again).\n\n### `analytics` (Function | Boolean, default: a function that pushes `_gaq` `_trackPageview` or sends `ga` `pageview`\n\nFunction that allows you to add behavior for analytics. By default it tries to track\na pageview with Google Analytics (if it exists on the page). It's called every time a page is switched, even for history navigation.\n\nSet to `false` to disable this behavior.\n\n### `scrollTo` (Integer | \\[Integer, Integer\\] | False, default: `0`)\n\nWhen set to an integer, this is the value (in px from the top of the page) to scroll to when a page is switched.\n\nWhen set to an array of 2 integers (\\[x, y\\]), this is the value to scroll both horizontally and vertically.\n\nSet this to `false` to disable scrolling, which will mean the page will stay in that same position it was before loading the new elements.\n\n### `scrollRestoration` (Boolean, default: `true`)\n\nWhen set to `true`, Pjax will attempt to restore the scroll position when navigating backwards or forwards.\n\n### `cacheBust` (Boolean, default: `true`)\n\nWhen set to `true`, Pjax appends a timestamp query string segment to the requested URL in order to skip the browser cache.\n\n### `debug` (Boolean, default: `false`)\n\nEnables verbose mode. Useful to debug page layout differences.\n\n### `currentUrlFullReload` (Boolean, default: `false`)\n\nWhen set to `true`, clicking on a link that points to the current URL will trigger a full page reload.\n\nWhen set to `false`, clicking on such a link will cause Pjax to load the current page without a full page reload. If you want to add some custom behavior, add a click listener to the link and call `preventDefault()`. This will prevent Pjax from receiving the event.\n\n**Note**: This must be done before Pjax is instantiated, otherwise Pjax's event handler will be called first, and `preventDefault()` won't have been called yet.\n\nHere is some sample code:\n\n```js\n  var links = document.querySelectorAll(\".js-Pjax\");\n\n  for (var i = 0; i \u003c links.length; i++) {\n    var el = links[i]\n\n    el.addEventListener(\"click\", function(e) {\n      if (el.href === window.location.href.split(\"#\")[0]) {\n        e.preventDefault();\n\n        console.log(\"Link to current page clicked\");\n        // Custom code goes here.\n      }\n    })\n  }\n\n  var pjax = new Pjax()\n```\n\n(Note that if `cacheBust` is set to `true`, the code that checks if the href is the same as the current page's URL will not work, due to the query string appended to force a cache bust).\n\n### `timeout` (Integer, default: `0`)\n\nThe timeout in _milliseconds_ for the XHR requests. Set to `0` to disable the timeout.\n\n## Events\n\nPjax fires a number of events regardless of how it's invoked.\n\nAll events are fired from the _document_, not the link that was clicked.\n\n* `pjax:send` - Fired after the Pjax request begins.\n* `pjax:complete` - Fired after the Pjax request finishes.\n* `pjax:success` - Fired after the Pjax request succeeds.\n* `pjax:error` - Fired after the Pjax request fails. The request object will be passed along as `event.options.request`.\n\n`send` and `complete` are a good pair of events to use if you are implementing a loading indicator (eg: [topbar](http://buunguyen.github.io/topbar/))\n\n```js\ndocument.addEventListener('pjax:send', topbar.show)\ndocument.addEventListener('pjax:complete', topbar.hide)\n```\n\n## HTTP Headers\n\nPjax uses several custom headers when it makes and receives HTTP requests. If the requests are going to your server, you can use those headers for some meta information about the response.\n\n### Request Headers\n\nPjax sends the following headers with every request:\n\n- `X-Requested-With: \"XMLHttpRequest\"`\n- `X-PJAX: \"true\"`\n- `X-PJAX-Selectors`:\n    A serialized JSON array of selectors, taken from `options.selectors`. You can use this to send back only the elements that Pjax will use to switch, instead of sending the whole page. Note that you'll need to deserialize this on the server (Such as by using `JSON.parse()`)\n\n### Response Headers\n\nPjax looks for the following headers on the response:\n\n- `X-PJAX-URL` or `X-XHR-Redirected-To`\n\nPjax first checks the `responseURL` property on the XHR object to see if the request was redirected by the server. Most browsers support this, but not all. To ensure Pjax will be able to tell when the request is redirected, you can include one of these headers with the response, set to the final URL.\n\n## DOM Ready State\n\nMost of the time, you will have code related to the current DOM that you only execute when the DOM is ready.\n\nSince Pjax doesn't automatically re-execute your previous code each time you load a page, you'll need to add code to re-trigger the DOM ready code. Here's a simple example:\n\n```js\nfunction whenDOMReady() {\n  // do your stuff\n}\n\nwhenDOMReady()\n\nvar pjax = new Pjax()\n\ndocument.addEventListener(\"pjax:success\", whenDOMReady)\n```\n\n_Note: Don't create the Pjax instance in the `whenDOMReady` function._\n\nIf you want to just update a specific part (which is a good idea), you can add the DOM-related code in a function and re-execute this function when the `pjax:success` event is fired.\n\n```js\n// do your global stuff\n//... DOM ready code\n\nfunction whenContainerReady() {\n  // do your container related stuff\n}\n\nwhenContainerReady()\n\nvar pjax = new Pjax()\n\ndocument.addEventListener(\"pjax:success\", whenContainerReady)\n```\n\n## FAQ\n\n### Q: Disqus doesn't work anymore, how can I fix that ?\n\n#### A: There are a few things you need to do:\n\n- Wrap your Disqus snippet into a DOM element that you will add to the `selector` property (or just wrap it with `class=\"js-Pjax\"`) and be sure to have at least an empty wrapper on each page (to avoid differences of DOM between pages).\n\n- Edit your Disqus snippet like the one below.\n\n#### Disqus snippet _before_ Pjax integration\n\n```html\n\u003cscript\u003e\n  var disqus_shortname = 'YOURSHORTNAME'\n  var disqus_identifier = 'PAGEID'\n  var disqus_url = 'PAGEURL'\n  var disqus_script = 'embed.js'\n\n  (function(d,s) {\n  s = d.createElement('script');s.async=1;s.src = '//' + disqus_shortname + '.disqus.com/'+disqus_script;\n  (d.getElementsByTagName('head')[0]).appendChild(s);\n  })(document)\n\u003c/script\u003e\n```\n\n#### Disqus snippet _after_ Pjax integration\n\n```html\n\u003cdiv class=\"js-Pjax\"\u003e\u003c!-- needs to be here on every Pjax-ified page, even if empty --\u003e\n\u003c!-- if (some condition) { // eventual server-side test to know whether or not you include this script --\u003e\n  \u003cscript\u003e\n    var disqus_shortname = 'YOURSHORTNAME'\n    var disqus_identifier = 'PAGEID'\n    var disqus_url = 'PAGEURL'\n    var disqus_script = 'embed.js'\n\n    // here we will only load the disqus \u003cscript\u003e if not already loaded\n    if (!window.DISQUS) {\n      (function(d,s) {\n      s = d.createElement('script');s.async=1;s.src = '//' + disqus_shortname + '.disqus.com/'+disqus_script;\n      (d.getElementsByTagName('head')[0]).appendChild(s);\n      })(document)\n    }\n    // if disqus \u003cscript\u003e is already loaded, we just reset disqus the right way\n    // see https://help.disqus.com/developer/using-disqus-on-ajax-sites\n    else {\n      DISQUS.reset({\n        reload: true,\n        config: function () {\n          this.page.identifier = disqus_identifier\n          this.page.url = disqus_url\n        }\n      })\n    }\n  \u003c/script\u003e\n\u003c!-- } --\u003e\n\u003c/div\u003e\n```\n\n**Note: Pjax only handles inline `\u003cscript\u003e` blocks for the container you are switching.**\n\n## Examples\n\nClone this repository and run `npm run example`, which will open the example app in your browser.\n\n## CONTRIBUTING\n\n- ⇄ Pull requests and ★ Stars are always welcome.\n- For bugs and feature requests, please create an issue.\n- Pull requests must be accompanied by passing automated tests (`npm test`). If the API is changed, please update the Typescript definitions as well (`pjax.d.ts`).\n\n## [CHANGELOG](CHANGELOG.md)\n\n## [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoox%2Fpjax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoox%2Fpjax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoox%2Fpjax/lists"}