Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pjax-api

Package Overview
Dependencies
Maintainers
0
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pjax-api

The advanced PJAX superior to SPA.

  • 3.44.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
297
increased by84.47%
Maintainers
0
Weekly downloads
 
Created
Source

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)

Keywords

FAQs

Package last updated on 12 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc