downtime
v0.1.1
Published
Background tasks API abstraction. Do background work during browser idle time.
Downloads
3
Maintainers
Readme
downtime
Do background work during browser idle time.
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
downtime.do(function(deadline) {
// Do background work
})
downtime.dont(id)
- Cancel callback represented by
id
var id = downtime.do(doBackgroundWork)
downtime.dont(id)
Notes
- Downtime uses
requestIdleCallback
andcancelIdleCallback
where available - Fallback technique is based on this gist
- For best performance, avoid DOM manipulation during idle time
Compatibility
- Native: caniuse: requestIdleCallback
- Fallback: any JavaScript environment