DEV Community

Cover image for An espresso shot of "Smooth": requestIdleCallback in <256 characters
Mike Talbot ⭐
Mike Talbot ⭐

Posted on

An espresso shot of "Smooth": requestIdleCallback in <256 characters

This is a submission for DEV Challenge v24.03.20, One Byte Explainer: Browser API or Feature.

Explainer

Keep your UI silky smooth by running code in the spare time at the end of each animation frame. requestIdleCallback allows you to provide a function to run in the frame gaps. Your function can query the amount of time left for the next step of your logic.

Top comments (4)

Collapse
 
link2twenty profile image
Andrew Bone

The three most liked ones of these are all performance related (yours, mine and @ben 's). I wonder if that says something about what people struggle with in JS or just what we focus on 😅

Collapse
 
ben profile image
Ben Halpern

That is an interesting remark.

Could be the kind of thing that people were just influenced by some of the first ones being performance-related and getting that in their mind?

I'd also say that a lot of performance-related APIs are sort of newer, quiet rollouts in the browsers from my perspective. They don't always get the same attention when they launch. So when you know about it you want to share the secret with others.

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Yeah I've not used matchMedia and I should. These things do just kinda "appear" as Ben says. There is nothing worse than seeing your beautiful design glitch away on someone else's computer!

Collapse
 
best_codes profile image
Best Codes

Never knew about this. Good summary; cool code.
Thanks! 🙂