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

benice

v1.0.3

Published

Be nice to host, run "onIdle"

Downloads

13

Readme

Benice - Be nice to your host!

Benice is a tiny set of browser performance estimation tools inspired by Dan Kaminsky's stupidly simple, genius "nice.js". It enables you to "be nice" to your surrounding hosting environment by running your logic only when the browser is estimated idle enough to handle it gracefully, thus reducing "hogging" resources, and slowing down fellow scripts. Benice also provides you with a rudimentary "Monitor" function that reports periodic estimations regarding how "idle" the browser is.

Installation

Benice is UMD compatible, and is available through:

onIdle

If your script is used on a 3rd party site, among many other scripts unknown to you, and you wish to defer your js code execution until the user's browser is relatively "idle", use:

var Benice = require('benice');

var stopWaiting = Benice.onIdle(function(){
    // Put your unobtrusive logic here
    console.log("Browser's Idle, nice time to show up!");
});

To cancel this wait for onIdle, simply call the function returned by `onIdle()':

stopWaiting();  // Wait is canceled, your code will never get executed

You can further tweak onIdle's behaviour using the following parameters:

onIdle(functionToExecute, detectionExpiration, resolutionSamples, sampleInterval, sampleThreshold, arg1, arg2, arg3...)

  • functionToExecute - The function to be run when an estimated "idle" state is successfully detected
  • detectionExpiration - A time interval (in milliseconds) after which functionToExecute will run regardless of a successful detection (defaults to 60000ms)
  • resolutionSamples - The number of samples requires to establish an "idle" estimation (defaults to 5 samples)
  • sampleInterval - The time interval used between samples (defaults to 150ms)
  • sampleThreshold - The sample threshold used to assume "idleness" (defaults to 50ms)
  • arg1, arg2, arg3... - The arguments to be used when calling functionToExecute.

For example:

The following call will exhaust detecting for browser idleness after 1 seconds:

onIdle(function(){ console.log('Detection attempt will exhaust in 1 second') }, 1000);

This one will require 10 samples to conclude that the browser is actually idle:

onIdle(function(){ console.log('After taking 10 samples, it is safe to estimate that the browser\'s idle') }, 60000, 10);

Monitor(functionToExecute, sampleInterval)

Monitor will call functionToExecute every sampleInterval passing it a coarse value ("samples") implying the browser's "idleness" state. 0 means "idle", X value (positive or negative) means X less idle. The simple method of establishing these values is explained in this Dan Kaminsky DEFCON talk.

You can abort a Monitor interval by calling the function it returns:

var stopMonitoring = Monitor(..);
stopMonitoring();

Examples

Page performance analyzer Page performance analyzer