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)
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 π
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.
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!Never knew about this. Good summary; cool code.
Thanks! π