npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pjax-api

v3.44.0

Published

The advanced PJAX superior to SPA.

Downloads

482

Readme

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*1|SPA on Pjax| |:-----|:---------------:|:---------:| |Type|Framework|Library| |Abstraction level|High|Low| |Original template language|Yes|No| |Intermediate layer|Yes|No| |Data format|JSON|JSON or anything*2| |UX integrity*3|Low|High| |Technical property|Exclusive|Coexistence| |Ecosystem|Dedicated|Common| |Old servers|Dispose|Keep| |New servers|Required|Optional| |Work on servers|Redevelop all|Add JSON APIs*4| |Work on clients|Redevelop all|Reconstruct scripts*5| |Partial introduction|Coarse|Fine| |Location|Servers and Clients|Clients| |Server constraints|Strong|Nothing| |Dependence|High|Low| |Learning costs|High|Low| |Development costs|High|Low| |Operation costs|High|Low| |Running costs|High|Low| |Removal costs|High|Low| |Renewal costs|High|Low|

*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

|Feature|defunkt|Turbolinks|falsandtru|Barba| |:------|:-----:|:--------:|:--------:|:---:| |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)