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

auto-progress

v1.1.0

Published

Automatically tracks the loading progress of your page

Downloads

7

Readme

AutoProgress JS

A JS module that automatically tracks the loading progress of your page.

Features

  • Automagically tracks loaded images, media elements, XHRs and fetches
  • Doesn't implement a visual progress bar, you can use whatever you want
  • Super lightweight (5kb minified, 2kb gzipped)
  • No runtime dependencies
  • Theoretically, runs on any browser (>=IE8), thanks to the wonders of Babel and Ctrl+C-Ctrl+V polyfills
  • Great for single page apps

Install

NPM

npm install auto-progress --save

Import it as soon as you can in your script

Script Tag Include before any other script

<script src="unpkg.com/auto-progress/dist/index.js" />

Usage

AutoProgress starts immediately after import, and searches for trackable elements on tha page (images, HTML5 media elements, XHRs, fetches). The module emits events to let you know if something happens. Use the getProgress method to get the current progress:

AutoProgress.onprogress = function () {
	console.log('An element just loaded.');
	// When not using arrow functions or addEventListener this = AutoProgress
	console.log('Total progress: ', this.getProgress());
};

AutoProgress.onfinished = function () {
	console.log('Finished loading!');
};

Of course, it wouldn't be too useful if you could only track the progress once, when the page loads. That's why the progress can be restarted. Manual restart:

AutoProgress.restart();

By default restart will be called automatically when

  • pushState or replaceState is called
  • popstate (back/forward button pressed) fires
  • If the history API is not supported the hash changes

If it is possible that something might keep your page from loading, you can set up a timeout, which will finish tracking the progress after the given time:

AutoProgress.setLoadTimeout(3000); // Miliseconds

You can customize the behaviour of the module with the setOption and setOptions methods Avalaible options:

  • restartOnPopstate(bool) Enables/disables restarting on popstate or pushState/replaceState. Default: true
  • fallbackHashChange (bool) Enables/disables restarting on hash change when history is not supported. Default: true
  • restartOnHashChange(bool) Enables/disables always restarting on hash change. Default: false
  • restartCooldown(number) Defines how much time has to pass between two restarts .Default: 1000
  • waitAfterStart(number) Defines how much time does a tracker wait for elements to track. Default: 100

Under the hood, AutoProgress after starting waits a set time for trackable objects to appear. (100ms by default). If it didn't find any elements (images, Ajax requests, etc.) that object type will be reported done. In the case of images and media elements they are only checked once after starting, so if it can't find any at that time, it will report them done until the next restart. XHRs and fetches however are constantly tracked, so if it finds at least one int the given time limit, new ones will be detected even after the time limit has expired.

Compatibility

Only tested in Firefox 58; Chrome 64; IE 11; and Edge 41

Possible Future Features

  • Trackable API for custom objects

License

MIT