Facebook makes its first browser API contribution


Facebook today announced that it has made its first major API contribution to Google’s Chrome browser. Together with Google, Facebook’s team created an API proposal to contribute code to the browser, which is a first for the company. The code, like so much of Facebook’s work on web tools and standards, focuses on making the user experience a bit smoother and faster. In this case, that means shortening the time between a click or keystroke and the browser reacting to that.

The first trial for this new system will launch with Chrome 74.

Typically, a browser’s JavaScript engine handles how code is executed and when it will halt for a moment to see if there are any pending input events to which it needs to react. Because even modern JavaScript engines that run on multi-core machines are still essentially single-threaded, the engine can only really do one thing at a time, so the trick is to figure out how to best combine code execution with checking 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,” the Facebook team explains in today’s announcement. “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.”

Every time the browser goes through that cycle, though, and checks for new events, processes them, a bit of extra time passes. You do this too many times and loading the page slows down. But if you only check for inputs at slower intervals, the user experience degrades as the browser takes longer to react.

[Read More]