Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanve/downtime
Do background work during browser idle time.
https://github.com/ryanve/downtime
javascript performance
Last synced: about 1 month 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 (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-23T19:35:30.000Z (almost 7 years ago)
- Last Synced: 2024-05-02T00:08:37.807Z (7 months ago)
- Topics: javascript, performance
- Language: JavaScript
- Homepage: https://npm.im/downtime
- Size: 14.6 KB
- Stars: 3
- Watchers: 1
- 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