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

vpjax

v0.8.2

Published

You can save your visitors from reloading resources every time they switch pages. In addition, since the whole process is asynchronous, it will provide a great experience by providing a faster transition.

Downloads

17

Readme

Vanilla JS + pushState = vPjax

You can save your visitors from reloading resources every time they switch pages. In addition, since the whole process is asynchronous, it will provide a great experience by providing a faster transition.

Get Started

NPM

npm install vpjax

CDN

https://unpkg.com/vpjax

How to Use?

So, it's very easy. You just need to instantiate a class where you mark the trigger selector and container element selector. You can also perform external actions by adding a listener for events that occur while running. According to the X-VPJAX header that comes with the request in the server output, you can trim the parts that you do not want to be sent again.


// When instantiating the class we send a flag to the constructor method pointing to the trigger and the container.
const vanillaPjax = new vPjax('a:not([target="_blank"])', '#wrap').init()
// Or we can send more flag as an object. As follows...
const vanillaPjax = new vPjax({
  selector: 'a:not([target="_blank"])', // element selector to be based on if clicked
  wrap: '#wrap', // container selector to base on query result
  formSelector: 'form[data-vpjax]', // form selector to be used as a basis for form submission operations
  cacheExpire: 500, // cache time in ms
  timeOut: 2000 // timeout in ms
}).init()

// And with form submit support.
const vanillaPjax = new vPjax('a:not([target="_blank"])', '#wrap').form('[data-vpjax]').init()

// You can also use it as below to reload the page.
vanillaPjax.reload(); // current
// or
vanillaPjax.reload("https://site-address.com"); // another

For events;

document.addEventListener("vPjax:start", (e) => {
  // NProgress.start(); // If you are using a progress-bar library, you can use it as in the example.
})

document.addEventListener("vPjax:finish", (e) => {
  // NProgress.done(); // If you are using a progress-bar library, you can use it as in the example.
});

// Other events
document.addEventListener("vPjax:click", (e) => {
  // Actions to be taken when a click is received for the new page.
})

document.addEventListener("vPjax:submit", (e) => {
  // Actions to take when form submission is triggered.
})

document.addEventListener("vPjax:beforeSend", (e) => {
  // Actions to be taken just before the asynchronous request starts.
})

document.addEventListener("vPjax:timeout", (e) => {
  // Actions to take when timeout occurs.
})

document.addEventListener("vPjax:success", (e) => {
  // Actions to be taken when the server response is successfully received.
})

document.addEventListener("vPjax:beforeExtract", (e) => {
  // Actions to be taken before DOM update starts.
})

document.addEventListener("vPjax:error", (e) => {
  // Actions to take when an error occurs.
})

document.addEventListener("vPjax:popstate", (e) => {
  // Actions to be taken when going backwards or forwards.
})

You can perform server-side request control on the server as in the example below.

  
  if (isset($_SERVER['HTTP_X_VPJAX']) !== false) {
    // For new page loads with vPJAX.
  } else {
    // The part you will use for the first load.
  }
  

Inspired by: jquery-pjax [https://github.com/defunkt/jquery-pjax]