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

better-ajaxify

v3.0.0-beta.5

Published

A simple PJAX engine for websites

Downloads

6

Readme

better-ajaxifyNPM version NPM downloads Build Status Coverage Status Twitter

A simple PJAX engine for websites

The library helps to solve the performance problem for HTML pages and also improves user experience. There is a term called "Full AJAX website" that defines a web site that instead of regular links or forms uses AJAX requests. After including an extra library on your page and simple adaptation on backend each navigation change triggers a partial reload instead of full refetching and rerendering of the whole page. That experience is always faster and nicer: user doesn't see white flashes, moreover you can show cool animations instead.

LIVE DEMO

Index

Installing

Library distributed via NPM:

$ npm install better-ajaxify --save-dev

This will clone the latest version of the better-ajaxify into the node_modules directory at the root of your project.

Then append the following html elements on your page:

<script src="node_modules/better-ajaxify/dist/better-ajaxify.js"></script>

Links

HTML element <a> allows to navigate to a url. Library modifies this behavior to prevent a white flash. Request to server is made using Fetch API, and response body replaces the current document without a full page reload.

In some cases regular <a> behavior preserved:

  • when href attribute value has only a hash;
  • when <a> has non-empty target attribute;
  • when <a> has non-http(s) url as the href attribute value (tel:, mailto: etc.).

Methods from the list above can be used in markup. When you need to keep regular <a> behavior in JavaScript - call method Event#preventDefault inside your click event handler for an appropriate element.

Forms

HTML element <form> serializes user input data and to sumbits it to new server url specified in the action attribute. Then browser triggers full page reload with the new url. Library modifies this behavior to prevent a white flash. Request to server is made using Fetch API, and response body replaces the current document without a full page reload.

In some cases regular <form> behavior is not modified:

  • when a <form> has non-empty target attribute;
  • when a <form> has non-http(s) url as the action attribute value (tel:, mailto: etc.).

Methods from the list above can be used in markup. When you need to keep regular <form> behavior in JavaScript - call method Event#preventDefault inside your submit event handler for an appropriate element.

Custom events

The library exposes set of custom events for advanced interaction.

| Event name | Type of Event#detail | Description | | ---------- | --------- | ----------- | | ajaxify:serialize | FormData | Event is trigerred for forms only and contains user input data | | ajaxify:fetch | Request | Event is trigerred when a navigation AJAX request started with request details | | ajaxify:load | Response | Event is trigerred when a navigation AJAX request ends and contains server response data | | ajaxify:render | Document | Triggered when a web page ready to update it's visual state to a new one |

Browser support

Desktop

  • Chrome
  • Safari 6.0+
  • Firefox 16+
  • Opera 12.10+
  • Internet Explorer 8+ (see notes)

Mobile

  • iOS Safari 6+
  • Android 2.3+
  • Chrome for Android