https://github.com/ryanve/downtime
Do background work during browser idle time.
https://github.com/ryanve/downtime
javascript performance
Last synced: 19 days ago
JSON representation
Do background work during browser idle time.
- Host: GitHub
- URL: https://github.com/ryanve/downtime
- Owner: ryanve
- License: isc
- Created: 2017-08-05T05:45:04.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-23T19:35:30.000Z (over 8 years ago)
- Last Synced: 2026-05-11T21:07:02.445Z (about 2 months ago)
- Topics: javascript, performance
- Language: JavaScript
- Homepage: https://npm.im/downtime
- Size: 14.6 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# downtime
[Do background work during browser idle time](https://www.w3.org/TR/requestidlecallback/).
```js
const downtime = require("downtime")
```
## API
### `downtime.do(callback)`
- Schedule `callback` to run during next idle period
- Return an `id` for cancellation purposes
- Callback is invoked with an `IdleDeadline` object
```js
downtime.do(function(deadline) {
// Do background work
})
```
### `downtime.dont(id)`
- Cancel callback represented by `id`
```js
var id = downtime.do(doBackgroundWork)
downtime.dont(id)
```
## Notes
- Downtime uses `requestIdleCallback` and `cancelIdleCallback` where available
- Fallback technique is based on [this gist](https://gist.github.com/paullewis/55efe5d6f05434a96c36)
- For [best performance](https://developers.google.com/web/updates/2015/08/using-requestidlecallback), avoid DOM manipulation during idle time
## Compatibility
- Native: [caniuse: requestIdleCallback](https://caniuse.com/#feat=requestidlecallback)
- Fallback: any JavaScript environment