3.44.0 • Published 3 months ago

pjax-api v3.44.0

Weekly downloads
93
License
(Apache-2.0 AND M...
Repository
github
Last release
3 months ago

PJAX

CI

The advanced PJAX superior to SPA.

The pjax-api can implement SPA on Pjax less expensive than SPA frameworks. And provides almost complete original web experience. Most SPA frameworks and pjax libraries lack many essential functions to keep the original web experience such as follows.

  • Browser history fix (Fix for browsers)
    • Browsers set the wrong title to the current URL in page back/forward.
  • Scroll position restoration (Fix for browsers)
    • Browsers cannot restore the scroll position if the current content doesn't have sufficient scroll size.
  • Unexpected scroll prevention (Fix for browsers)
    • Browsers unexpectedly scroll the page before updating the page in page back/forward.
  • Scroll behaviors around hash links
    • Most frameworks and libraries reproduce wrong scroll behaviors around hash links.
  • Scroll position after reloading
    • Most frameworks break the current scroll position after reloading.

Properties

Pjax is a low-level API for SPA easier, simpler, and less expensive than high-level APIs of SPA frameworks.

// SPA on Pjax
import Pjax, { FakeXMLHttpRequest } from 'pjax-api';

new Pjax({
  fetch: {
    rewrite: url =>
      FakeXMLHttpRequest.create(
        url,
        fetch(url, { headers: { 'Content-Type': 'application/json' } })
          .then(res => res.json())
          .then(data =>
            new DOMParser().parseFromString(
              `<title>${data.title}</title><body>${data.body}</body>`,
              'text/html'))),
  },
});
SPA on frameworks*1SPA on Pjax
TypeFrameworkLibrary
Abstraction levelHighLow
Original template languageYesNo
Intermediate layerYesNo
Data formatJSONJSON or anything*2
UX integrity*3LowHigh
Technical propertyExclusiveCoexistence
EcosystemDedicatedCommon
Old serversDisposeKeep
New serversRequiredOptional
Work on serversRedevelop allAdd JSON APIs*4
Work on clientsRedevelop allReconstruct scripts*5
Partial introductionCoarseFine
LocationServers and ClientsClients
Server constraintsStrongNothing
DependenceHighLow
Learning costsHighLow
Development costsHighLow
Operation costsHighLow
Running costsHighLow
Removal costsHighLow
Renewal costsHighLow

1 Such as React. 2 You can send any efficient format instead of JSON and parse it on clients. 3 Between MPA(standard web sites) and SPA. 4 Just do it. *5 To manage the lifetime of existing scripts. Since such management doesn't depend on SPA, these scripts are sharable and reusable with MPA and other SPA libraries.

SPA frameworks are cancer of the web.

Features

FeaturedefunktTurbolinksfalsandtruBarba
SPA on Pjax (Use JSON instead of HTML)
Multiple area update
Fallback area matching
Shadow DOM support
Content type verification
HEAD contents markless auto sync
CSS markless auto sync
Script markless auto load
External script load
Inline script execution
Execution sequence keeping
Non-blocking script load
Subresource integrity verification*1
Rewrite request and response (XHR)
Rewrite source document
Concurrent sequence integration
URL scope
Browser history fix
Scroll position restoration
Unexpected scroll prevention
NOSCRIPT tag fix
History API support*2
No jQuery dependency

1 Excludes ES modules. 2 Ability to use pjax APIs and history APIs in combination.

Documents

https://falsandtru.github.io/pjax-api

Install

CDN

https://www.jsdelivr.com/package/npm/pjax-api

npm

$ npm i pjax-api

Usage

Note that this example specifies the latest version. You have to replace it with any specific version to preserve APIs from breaking changes.

<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'
  ]
});

Browsers

  • Chrome
  • Firefox
  • Safari
  • Edge (Chromium edition only)
3.44.0

3 months ago

3.43.0

3 months ago

3.42.0

3 months ago

3.41.1

6 months ago

3.40.0

8 months ago

3.40.1

8 months ago

3.40.2

8 months ago

3.40.3

8 months ago

3.40.4

8 months ago

3.40.5

8 months ago

3.41.0

8 months ago

3.39.0

8 months ago

3.39.1

8 months ago

3.38.2

11 months ago

3.38.3

9 months ago

3.38.4

8 months ago

3.38.5

8 months ago

3.38.1

1 year ago

3.36.0

2 years ago

3.36.1

2 years ago

3.37.0

2 years ago

3.37.1

2 years ago

3.38.0

2 years ago

3.35.3

2 years ago

3.35.4

2 years ago

3.35.0

2 years ago

3.35.1

2 years ago

3.35.2

2 years ago

3.34.0

2 years ago

3.33.4

2 years ago

3.33.5

2 years ago

3.33.3

3 years ago

3.33.2

3 years ago

3.33.1

3 years ago

3.33.0

4 years ago

3.32.0

4 years ago

3.31.1

4 years ago

3.31.2

4 years ago

3.31.0

4 years ago

3.30.1

4 years ago

3.30.0

4 years ago

3.29.11

4 years ago

3.29.10

5 years ago

3.29.9

5 years ago

3.29.8

5 years ago

3.29.7

5 years ago

3.29.6

5 years ago

3.29.5

5 years ago

3.29.4

5 years ago

3.29.3

5 years ago

3.29.2

5 years ago

3.29.1

5 years ago

3.29.0

5 years ago

3.28.4

5 years ago

3.28.3

5 years ago

3.28.2

5 years ago

3.28.1

5 years ago

3.28.0

5 years ago

3.27.2

5 years ago

3.27.1

5 years ago

3.27.0

5 years ago

3.26.2

5 years ago

3.26.1

5 years ago

3.26.0

5 years ago

3.25.0

5 years ago

3.24.2

5 years ago

3.24.1

5 years ago

3.24.0

5 years ago

3.23.0

6 years ago

3.22.0

6 years ago

3.21.3

6 years ago

3.21.2

6 years ago

3.21.1

6 years ago

3.21.0

6 years ago

3.20.3

6 years ago

3.20.2

6 years ago

3.20.1

6 years ago

3.20.0

6 years ago

3.19.0

6 years ago

3.18.2

6 years ago

3.18.1

6 years ago

3.18.0

6 years ago

3.17.8

6 years ago

3.17.7

7 years ago

3.17.6

7 years ago

3.17.5

7 years ago

3.17.4

7 years ago

3.17.3

7 years ago

3.17.2

7 years ago

3.17.1

7 years ago

3.17.0

7 years ago

3.16.11

7 years ago

3.16.10

7 years ago

3.16.9

7 years ago

3.16.8

7 years ago

3.16.7

7 years ago

3.16.6

7 years ago

3.16.5

7 years ago

3.16.4

7 years ago

3.16.3

7 years ago

3.16.2

7 years ago

3.16.1

7 years ago

3.16.0

7 years ago

3.15.2

7 years ago

3.15.1

7 years ago

3.15.0

7 years ago

3.14.1

7 years ago

3.14.0

7 years ago

3.13.0

7 years ago

3.12.2

7 years ago

3.12.1

7 years ago

3.12.0

7 years ago

3.11.2

7 years ago

3.11.1

7 years ago

3.11.0

7 years ago

3.10.4

7 years ago

3.10.3

7 years ago

3.10.2

7 years ago

3.10.1

7 years ago

3.10.0

7 years ago

3.9.3

7 years ago

3.9.2

7 years ago

3.9.1

7 years ago

3.9.0

7 years ago

3.8.0

7 years ago

3.7.0

7 years ago

3.6.1

7 years ago

3.6.0

7 years ago

3.5.4

7 years ago

3.5.3

7 years ago

3.5.2

7 years ago

3.5.1

7 years ago

3.5.0

7 years ago

3.4.4

7 years ago

3.4.3

7 years ago

3.4.2

7 years ago

3.4.1

7 years ago

3.4.0

7 years ago

3.3.6

8 years ago

3.3.5

8 years ago

3.3.4

8 years ago

3.3.3

8 years ago

3.3.2

8 years ago

3.3.1

8 years ago

3.3.0

8 years ago

3.2.2

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

0.0.0

8 years ago