{"id":18654551,"url":"https://github.com/zeraphie/pjax","last_synced_at":"2025-09-11T16:02:57.952Z","repository":{"id":57405080,"uuid":"85098990","full_name":"zeraphie/pjax","owner":"zeraphie","description":"This is my own condensed pjax (pushstate + ajax) wrapper for super fast load times","archived":false,"fork":false,"pushed_at":"2018-01-22T14:52:25.000Z","size":135,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-17T23:38:43.357Z","etag":null,"topics":["ajax","history","javascript","onload","pjax","pushstate"],"latest_commit_sha":null,"homepage":null,"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/zeraphie.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-03-15T17:00:47.000Z","updated_at":"2024-07-11T10:16:12.000Z","dependencies_parsed_at":"2022-09-16T09:01:34.180Z","dependency_job_id":null,"html_url":"https://github.com/zeraphie/pjax","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zeraphie/pjax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeraphie%2Fpjax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeraphie%2Fpjax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeraphie%2Fpjax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeraphie%2Fpjax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeraphie","download_url":"https://codeload.github.com/zeraphie/pjax/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeraphie%2Fpjax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274665007,"owners_count":25327093,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","history","javascript","onload","pjax","pushstate"],"created_at":"2024-11-07T07:15:43.790Z","updated_at":"2025-09-11T16:02:57.919Z","avatar_url":"https://github.com/zeraphie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PJAX\nThis is my own condensed pjax (pushstate + ajax) library for super fast load times, has **no dependencies** and no additional server requirements\n\nIf you want to see a demo, have a look at my [github pages](https://zeraphie.github.io/) site!\n\n---\n\n## Installation\nThis is available as a package on npm so you can add this to your project by using npm or yarn\n\n**npm**\n```bash\nnpm install z-pjax\n```\n\n**yarn**\n```bash\nyarn add z-pjax\n```\n\n## Usage\nIn your main JavaScript file, import the class, setup the pjax object and then attach any functions that need to go onload with `pjax.onload`, which is a wrapper for `window.onload` and when the pjax request has finished\n\n```javascript\nimport PJAX from './src/PJAX';\n\nlet pjax = new PJAX();\n\nlet x = 0;\n\npjax.onload(() =\u003e {\n    x++;\n    \n    console.log(`Loaded ${x} times with pjax`);\n});\n\npjax.setup();\n```\n\n## Selecting data to PJAX\nThis library is able to replace various different elements on a webpage, it currently replaces the main content (body), the title tag, and then any matching attributes that you want.\n\n### Changing the `container` and `links`\nThe main functionality of PJAX is used in the `container` and `links` properties, and there are two ways of changing what these are (the defaults are `.body` and `.pjax-link`\n\n**Constructor**\n```javascript\nlet pjax = new PJAX('main', 'a');\npjax.setup();\n```\n\n**After Initialisation**\n```javascript\nlet pjax = new PJAX();\n\npjax.container = 'main';\npjax.links = 'a';\n\npjax.setup();\n```\n\n### Changing text content outside of the `container`\nSometimes elements outside of the `container` will need to change as well, such as the title of the page, or the h1 if it exists outside, in order to change what elements have their `textContent` property changed, the following is needed (these are also the defaults)\n\n```javascript\nlet pjax = new PJAX();\n\npjax.replace.textContent = [\n    'title'\n];\n\npjax.setup();\n```\n\n### Changing attributes outside of the `container`\nSometimes attributes of elements will also need to be changed, particularly ones related to SEO or Social media, this library also covers those, but if you need to change the behaviour, you'll need to do the following (these are also the defaults)\n\n```javascript\nlet pjax = new PJAX();\n\npjax.replace.attribute = [\n    {\n        selector: 'meta[name$=\"title\"]',\n        attribute: 'content'\n    },\n    {\n        selector: 'meta[name$=\"description\"]',\n        attribute: 'content'\n    },\n    {\n        selector: 'meta[property^=\"og:\"]',\n        attribute: 'content'\n    },\n    {\n        selector: 'meta[property^=\"article:\"]',\n        attribute: 'content'\n    },\n    {\n        selector: 'link[rel=\"canonical\"]',\n        attribute: 'href'\n    }\n];\n\npjax.setup();\n```\n\n---\n\n## Notes\nThis class uses the `forEach` method for nodelists, so if you need to support IE11 for some reason, add this polyfill in\n```javascript\nif(typeof NodeList.prototype.forEach === 'undefined'){\n    /* Polyfill for nodelist foreach for ie11 */\t\t\n    NodeList.prototype.forEach = function (callback, scope){\n        for(var i = 0; i \u003c this.length; i++){\n            callback.call(scope, this[i], i);\n        }\n    };\n}\n```\n\n---\n\n## Building\nIf for some reason, you want to build the files for this library yourself (instead of using the `dist` folder), you can run the following commands to work locally with it\n\n*Note: Don't forget to install the dev dependencies*\n\n**Running `gulp`\n```bash\ngulp # This command builds the files, then watches for any changes in the src directory\ngulp build # This command only builds the files\ngulp watch # This command only watches the files\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeraphie%2Fpjax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeraphie%2Fpjax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeraphie%2Fpjax/lists"}