PJAX stands for page-state + ajax. It allows pages to be loaded via ajax, but supports proper links / events / reloads etc. It also degrades gracefully if the content cannot be loaded.
Pretty easy. You need to do three things.
You'll need:
- The pjax js
- both the jquery plugin
- and mjax.js
- My pjax functions:
pjaxify
andpjax_html
$("//a[@class='mylinks']") {
pjaxify("#main")
}
What did we do here?
- We selected the links we want to load via pjax
- We added an attribute to these links
- This attribute is a css selector for the content you want pjax to suck out of the anchor's href
- The pjax JS sends along this selector in its request, which makes it easy for the server to respond w the proper content
If you wanted certain links to pjax different content, easy! This is specified w a different argument to pjaxify
pjax_html() {
# Normal tritium here
# ...
}
This responds to the headers that pjax sends via ajax (x-pjax
and x-pjax-container
). It extracts the title and content from the html and resets the response to be exactly what the pjax javascript expects.
- Open your inspector
- Look at the network tab
- Hit the 'XHR' filter so you only see ajax requests
- Hit the 'record' button so you see requests across page loads
- Go to this page
- If you click around you can see which links are enabled w pjax
- (The ones that load via XHR)
- And those links that are normal links
- If you click around you can see which links are enabled w pjax
This project works with the MoovSDK.
See detailed documentation for the MoovSDK at http://beta.moovweb.com
Remember to put all domains you're going to hit in your etc/hosts
or to run your server with the -auto-hosts=true
option.
127.0.0.1 mlocal.moovweb.com
127.0.0.1 mlocal.beta.moovweb.com