Questions tagged [requestidlecallback]

window.requestIdleCallback API is an experimental alternative to setTimeout for running a callback when only when the browser is not busy. This permits to give a lower priority to a task.

Documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback

6 questions
97
votes
1 answer

scroll events: requestAnimationFrame VS requestIdleCallback VS passive event listeners

As we know, it's often advised to debounce scroll listeners so that UX is better when the user is scrolling. However, I've often found libraries and articles where influential people like Paul Lewis recommend using requestAnimationFrame. However as…
3
votes
1 answer

What happen if a requestIdleCallback's callback is executed too long to finish in an idle period?

The callback function of a requestIdleCallback will be executed in the browser's idle period. If this callback costs too much time and couldn't be finished in an idle period. And if the user's interaction is coming, does the callback still to be…
Colin He
  • 31
  • 4
1
vote
1 answer

What is the best way to schedule a small task to execute as fast as possible, while still making it wait for UI updates?

I'm reading a bit about micro tasks and such, because at the moment I have a project that is poorly optimized and some tasks make the UI hang. I've solved 95% of that by using a (Service) Worker for the heaviest tasks. But there's still some code…
1
vote
1 answer

How do you flush requestIdleCallback in an Angular service test?

I'm writing an Angular service that uses requestIdleCallback to call another function, foo. In my test, I want to make sure that foo is being called eventually. Currently I have a test that looks like this: it('test', fakeAsync(() => { //…
Evan
  • 222
  • 3
  • 9
0
votes
1 answer

Does requestIdleCallback guarantee executation, and does it preserve order of execution?

Are functions passed to requestIdleCallback guaranteed to run when no timeout is specified? (Assuming we aren't in some contrived scenario, specifically engineered to avoid idle state indefinitiely) And if a timeout is specified, is there a…
Simon
  • 29
  • 6
0
votes
1 answer

Using requestAnimationFrame inside requestIdleCallback

If I animate changes in the DOM from JS (e.g. changing the value of a node's textContent from 1 to 500), would it be better to use requestAnimationFrame or requestAnimationFrame within a requestIdleCallback?