PJAX
The advanced PJAX superior to SPA.
Features
The pjax-api provides almost complete original web experience.
- Browser history fix
- Scroll position restoration
- Unexpected scroll prevention
- Scroll behaviors around hash links
- SPA on Pjax (Use JSON instead of HTML)
- More
Modes
Adding JSON APIs is the only change required on servers to enable SPA on Pjax.
JSON(SPA) mode is statically and dynamically configurable per URL scope on browsers.
- None (Offline)
- Send no requests.
- HTML (Pjax)
- Request an HTML response.
- JSON (SPA)
- Request a JSON response.
- Any
- Any response types are available in the same way as JSON.
- More
Usage
<script src="https://cdn.jsdelivr.net/npm/pjax-api@latest"></script>
<script src="/assets/js/config.js"></script>
// config.js
import Pjax from 'pjax-api';
// or
const { Pjax } = window['pjax-api'];
new Pjax({
areas: [
// Try the first query.
'#header, #primary',
// Retry using the second query
// if the first query doesn't match.
'#container',
// Retry.
'body'
]
});