0.1.1 • Published 8 years ago
downtime v0.1.1
downtime
Do background work during browser idle time.
const downtime = require("downtime")API
downtime.do(callback)
- Schedule
callbackto run during next idle period - Return an
idfor cancellation purposes - Callback is invoked with an
IdleDeadlineobject
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
requestIdleCallbackandcancelIdleCallbackwhere 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