
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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.
Benice is UMD compatible, and is available through:
npm install benice
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
will run regardless of a successful detection (defaults to 60000ms)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 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();
FAQs
Be nice to host, run "onIdle"
We found that benice demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.