[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3267":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},3267,"jquery-pjax","defunkt\u002Fjquery-pjax","defunkt","pushState + ajax = pjax","https:\u002F\u002Fpjax.herokuapp.com",null,"JavaScript",16647,1932,539,61,0,1,4,44.86,"MIT License",false,"master",[],"2026-06-12 02:00:48","# pjax = pushState + ajax\n\npjax is a jQuery plugin that uses ajax and pushState to deliver a fast browsing experience with real permalinks, page titles, and a working back button.\n\npjax works by fetching HTML from your server via ajax and replacing the content\nof a container element on your page with the loaded HTML. It then updates the\ncurrent URL in the browser using pushState. This results in faster page\nnavigation for two reasons:\n\n* No page resources (JS, CSS) get re-executed or re-applied;\n* If the server is configured for pjax, it can render only partial page\n  contents and thus avoid the potentially costly full layout render.\n\n### Status of this project\n\njquery-pjax is **largely unmaintained** at this point. It might continue to\nreceive important bug fixes, but _its feature set is frozen_ and it's unlikely\nthat it will get new features or enhancements.\n\n## Installation\n\npjax depends on jQuery 1.8 or higher.\n\n### npm\n\n```\n$ npm install jquery-pjax\n```\n\n### standalone script\n\nDownload and include `jquery.pjax.js` in your web page:\n\n```\ncurl -LO https:\u002F\u002Fraw.github.com\u002Fdefunkt\u002Fjquery-pjax\u002Fmaster\u002Fjquery.pjax.js\n```\n\n## Usage\n\n### `$.fn.pjax`\n\nThe simplest and most common use of pjax looks like this:\n\n``` javascript\n$(document).pjax('a', '#pjax-container')\n```\n\nThis will enable pjax on all links on the page and designate the container as `#pjax-container`.\n\nIf you are migrating an existing site, you probably don't want to enable pjax\neverywhere just yet. Instead of using a global selector like `a`, try annotating\npjaxable links with `data-pjax`, then use `'a[data-pjax]'` as your selector. Or,\ntry this selector that matches any `\u003Ca data-pjax href=>` links inside a `\u003Cdiv\ndata-pjax>` container:\n\n``` javascript\n$(document).pjax('[data-pjax] a, a[data-pjax]', '#pjax-container')\n```\n\n#### Server-side configuration\n\nIdeally, your server should detect pjax requests by looking at the special\n`X-PJAX` HTTP header, and render only the HTML meant to replace the contents of\nthe container element (`#pjax-container` in our example) without the rest of\nthe page layout. Here is an example of how this might be done in Ruby on Rails:\n\n``` ruby\ndef index\n  if request.headers['X-PJAX']\n    render :layout => false\n  end\nend\n```\n\nIf you'd like a more automatic solution than pjax for Rails check out [Turbolinks][].\n\n[Check if there is a pjax plugin][plugins] for your favorite server framework.\n\nAlso check out [RailsCasts #294: Playing with PJAX][railscasts].\n\n#### Arguments\n\nThe synopsis for the `$.fn.pjax` function is:\n\n``` javascript\n$(document).pjax(selector, [container], options)\n```\n\n1. `selector` is a string to be used for click [event delegation][$.fn.on].\n2. `container` is a string selector that uniquely identifies the pjax container.\n3. `options` is an object with keys described below.\n\n##### pjax options\n\nkey | default | description\n----|---------|------------\n`timeout` | 650 | ajax timeout in milliseconds after which a full refresh is forced\n`push` | true | use [pushState][] to add a browser history entry upon navigation\n`replace` | false | replace URL without adding browser history entry\n`maxCacheLength` | 20 | maximum cache size for previous container contents\n`version` | | a string or function returning the current pjax version\n`scrollTo` | 0 | vertical position to scroll to after navigation. To avoid changing scroll position, pass `false`.\n`type` | `\"GET\"` | see [$.ajax][]\n`dataType` | `\"html\"` | see [$.ajax][]\n`container` | | CSS selector for the element where content should be replaced\n`url` | link.href | a string or function that returns the URL for the ajax request\n`target` | link | eventually the `relatedTarget` value for [pjax events](#events)\n`fragment` | | CSS selector for the fragment to extract from ajax response\n\nYou can change the defaults globally by writing to the `$.pjax.defaults` object:\n\n``` javascript\n$.pjax.defaults.timeout = 1200\n```\n\n### `$.pjax.click`\n\nThis is a lower level function used by `$.fn.pjax` itself. It allows you to get a little more control over the pjax event handling.\n\nThis example uses the current click context to set an ancestor element as the container:\n\n``` javascript\nif ($.support.pjax) {\n  $(document).on('click', 'a[data-pjax]', function(event) {\n    var container = $(this).closest('[data-pjax-container]')\n    var containerSelector = '#' + container.id\n    $.pjax.click(event, {container: containerSelector})\n  })\n}\n```\n\n**NOTE** Use the explicit `$.support.pjax` guard. We aren't using `$.fn.pjax` so we should avoid binding this event handler unless the browser is actually going to use pjax.\n\n### `$.pjax.submit`\n\nSubmits a form via pjax.\n\n``` javascript\n$(document).on('submit', 'form[data-pjax]', function(event) {\n  $.pjax.submit(event, '#pjax-container')\n})\n```\n\n### `$.pjax.reload`\n\nInitiates a request for the current URL to the server using pjax mechanism and replaces the container with the response. Does not add a browser history entry.\n\n``` javascript\n$.pjax.reload('#pjax-container', options)\n```\n\n### `$.pjax`\n\nManual pjax invocation. Used mainly when you want to start a pjax request in a handler that didn't originate from a click. If you can get access to a click `event`, consider `$.pjax.click(event)` instead.\n\n``` javascript\nfunction applyFilters() {\n  var url = urlForFilters()\n  $.pjax({url: url, container: '#pjax-container'})\n}\n```\n\n## Events\n\nAll pjax events except `pjax:click` & `pjax:clicked` are fired from the pjax\ncontainer element.\n\n\u003Ctable>\n\u003Ctr>\n  \u003Cth>event\u003C\u002Fth>\n  \u003Cth>cancel\u003C\u002Fth>\n  \u003Cth>arguments\u003C\u002Fth>\n  \u003Cth>notes\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Cth colspan=4>event lifecycle upon following a pjaxed link\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:click\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>✔︎\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>fires from a link that got activated; cancel to prevent pjax\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:beforeSend\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>✔︎\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>can set XHR headers\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:start\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:send\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:clicked\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>fires after pjax has started from a link that got clicked\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:beforeReplace\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>contents, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>before replacing HTML with content loaded from the server\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:success\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>data, status, xhr, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>after replacing HTML content loaded from the server\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:timeout\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>✔︎\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>fires after \u003Ccode>options.timeout\u003C\u002Fcode>; will hard refresh unless canceled\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:error\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>✔︎\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, textStatus, error, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>on ajax error; will hard refresh unless canceled\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:complete\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, textStatus, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>always fires after ajax, regardless of result\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:end\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>xhr, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Cth colspan=4>event lifecycle on browser Back\u002FForward navigation\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:popstate\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>event \u003Ccode>direction\u003C\u002Fcode> property: &quot;back&quot;\u002F&quot;forward&quot;\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:start\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>null, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>before replacing content\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:beforeReplace\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>contents, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>right before replacing HTML with content from cache\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n  \u003Ctd>\u003Ccode>pjax:end\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>\u003C\u002Ftd>\n  \u003Ctd>\u003Ccode>null, options\u003C\u002Fcode>\u003C\u002Ftd>\n  \u003Ctd>after replacing content\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n`pjax:send` & `pjax:complete` are a good pair of events to use if you are implementing a\nloading indicator. They'll only be triggered if an actual XHR request is made,\nnot if the content is loaded from cache:\n\n``` javascript\n$(document).on('pjax:send', function() {\n  $('#loading').show()\n})\n$(document).on('pjax:complete', function() {\n  $('#loading').hide()\n})\n```\n\nAn example of canceling a `pjax:timeout` event would be to disable the fallback\ntimeout behavior if a spinner is being shown:\n\n``` javascript\n$(document).on('pjax:timeout', function(event) {\n  \u002F\u002F Prevent default timeout redirection behavior\n  event.preventDefault()\n})\n```\n\n## Advanced configuration\n\n### Reinitializing plugins\u002Fwidget on new page content\n\nThe whole point of pjax is that it fetches and inserts new content _without_\nrefreshing the page. However, other jQuery plugins or libraries that are set to\nreact on page loaded event (such as `DOMContentLoaded`) will not pick up on\nthese changes. Therefore, it's usually a good idea to configure these plugins to\nreinitialize in the scope of the updated page content. This can be done like so:\n\n``` js\n$(document).on('ready pjax:end', function(event) {\n  $(event.target).initializeMyPlugin()\n})\n```\n\nThis will make `$.fn.initializeMyPlugin()` be called at the document level on\nnormal page load, and on the container level after any pjax navigation (either\nafter clicking on a link or going Back in the browser).\n\n### Response types that force a reload\n\nBy default, pjax will force a full reload of the page if it receives one of the\nfollowing responses from the server:\n\n* Page content that includes `\u003Chtml>` when `fragment` selector wasn't explicitly\n  configured. Pjax presumes that the server's response hasn't been properly\n  configured for pjax. If `fragment` pjax option is given, pjax will extract the\n  content based on that selector.\n\n* Page content that is blank. Pjax assumes that the server is unable to deliver\n  proper pjax contents.\n\n* HTTP response code that is 4xx or 5xx, indicating some server error.\n\n### Affecting the browser URL\n\nIf the server needs to affect the URL which will appear in the browser URL after\npjax navigation (like HTTP redirects work for normal requests), it can set the\n`X-PJAX-URL` header:\n\n``` ruby\ndef index\n  request.headers['X-PJAX-URL'] = \"http:\u002F\u002Fexample.com\u002Fhello\"\nend\n```\n\n### Layout Reloading\n\nLayouts can be forced to do a hard reload when assets or html changes.\n\nFirst set the initial layout version in your header with a custom meta tag.\n\n``` html\n\u003Cmeta http-equiv=\"x-pjax-version\" content=\"v123\">\n```\n\nThen from the server side, set the `X-PJAX-Version` header to the same.\n\n``` ruby\nif request.headers['X-PJAX']\n  response.headers['X-PJAX-Version'] = \"v123\"\nend\n```\n\nDeploying a deploy, bumping the version constant to force clients to do a full reload the next request getting the new layout and assets.\n\n\n[$.fn.on]: http:\u002F\u002Fapi.jquery.com\u002Fon\u002F\n[$.ajax]: http:\u002F\u002Fapi.jquery.com\u002FjQuery.ajax\u002F\n[pushState]: https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FGuide\u002FAPI\u002FDOM\u002FManipulating_the_browser_history#Adding_and_modifying_history_entries\n[plugins]: https:\u002F\u002Fgist.github.com\u002F4283721\n[turbolinks]: https:\u002F\u002Fgithub.com\u002Frails\u002Fturbolinks\n[railscasts]: http:\u002F\u002Frailscasts.com\u002Fepisodes\u002F294-playing-with-pjax\n","pjax 是一个 jQuery 插件，它结合了 AJAX 和 HTML5 的 pushState 技术，为用户提供快速浏览体验的同时保持真实的永久链接、页面标题和可用的后退按钮。其核心功能在于通过 AJAX 从服务器获取 HTML 并替换页面上的指定容器内容，同时使用 pushState 更新浏览器地址栏，从而避免了页面资源（如 JS、CSS）的重新加载与执行，加快了页面切换速度。此外，如果服务器针对 pjax 进行优化，则可以仅渲染部分内容，进一步提升性能。适用于需要提高用户体验但又不想完全重写前端架构的网站，特别适合于已有站点的部分迁移或优化场景。",2,"2026-06-11 02:53:16","top_language"]