Facebook and Google have teamed up to create an Application Programming Interface (API) in the Chrome browser with the intention of speeding up the user experience, and making it smoother. This particular API aims to shorten the reaction times between a user input and the browser’s reaction, TechCrunch reported.
“At Facebook, we measure events at four stages: the moment the operating system gets the input, the moment we actually start processing it, the moment we start showing changes on the screen in response to the event, and the moment we finish processing it. As we looked at our top interactions, we noticed that queueing time was causing one of the biggest delays,” the company said.
“Queuing refers to the time between when a person interacts with a page (e.g., clicks or types) and when we actually start processing the event. In extreme cases, this delay can be frustrating. Imagine clicking a notifications icon, then having to wait a full minute for the button to indicate that it registered your click. You probably wouldn’t wait for it to finish loading.”
The trial for the new API will launch with Chrome 74. The way it usually works is a JavaScript engine will handle how the code is executed, but it will stop to see if there are any other inputs coming in. Because modern JavaScript engines on multi-core machines are still basically single-threaded, it can only do one thing at a time. Facebook and Google are trying to work out how to combine the work of executing the code with looking for input events.
“Like many other sites, we deal with this issue by breaking the JavaScript up into smaller blocks. While the page is loading, we run a bit of JavaScript, and then we yield and pass control back to the browser,” Facebook said. “The browser can then check its input event queue and see whether there is anything it needs to tell the page about. Then the browser can go back to running the JavaScript blocks as they get added.”
The engineers created the isInputPending API, which lets developers check whether any inputs are pending while also executing code.
“The process of bringing isInputPending to Chrome represents a new method of developing web standards at Facebook,” Facebook said. “We hope to continue driving new APIs and to ramp up our contributions to open source web browsers. Down the road, we could potentially build this API directly into React’s concurrent mode so developers would get the API benefits out of the box. In addition, isInputPending is now part of a larger effort to build scheduling primitives into the web.”