Forem

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

Posted on

9 3 2 2 3

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! 🙂

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay