Skip to content

ryanve/downtime

Repository files navigation

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 and cancelIdleCallback where available
  • Fallback technique is based on this gist
  • For best performance, avoid DOM manipulation during idle time

Compatibility