jan

jankdefer

An experiment to defer executing until the framerate in the page stabilizes

Showing:

Popularity

Downloads/wk

2

GitHub Stars

6

Maintenance

Last Commit

2yrs ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

0.4KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

jankdefer 🖥🔥

It's like domready, except it defers loading until the page framerate stabilizes. The idea is that if requestAnimationFrame is running slowly, then the page has either not loaded yet or the page is in a background tab.

This script ensures requestAnimationFrame runs at least 50fps for several frames before calling back.

See also: [requestIdleCallback|https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback]

Usage

Basic usage should be good enough for most scenarios:

const jankdefer = require('jankdefer');

jankdefer(myFunction);

Usage with options:

const jankdefer = require('jankdefer');

jankdefer(myFunction, {
  framerateTarget: 50,
  timeout: 3000,
  threshold: 5,
  debug: false,
});

Default options

PropertyDefaultDescription
framerateTarget50Wait until the system is running at least 50fps. (Some slower devices do not run at 60)
timeout3000Number of milliseconds after which the function will run anyway.
threshold5Wait at least this many successful runs before calling back.
debugfalsePrint debug info if you want to understand what's happening.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100