When I'm building web apps, I like to put a distinction between "important" code, and "superfluous". "Important" code being code that is required to run the app's features and is usually tied to a user interaction. "Superfluous" code is code that runs in the background and might handle such things as moving carousel images, checking for updates, or adding elements to a news feed.
When optimizing a web app, it seems like it would be a good idea to wrap any "superfluous" JS in a window.requestAnimationFrame()
to prevent it from blocking the more important JS and slowing down user interactions. Nearly all documented uses for window.requestAnimationFrame()
are related to animations, but I don't see why it couldn't be used in other contexts.
tl;dr: Are there any downsides to using window.requestAnimationFrame()
outside of animation-related code?