X
Business

How Facebook helped tweak Chrome and Firefox to download pages faster

Social media giant worked with browser teams to improve caching, sees web page downloads improve as a result.
Written by Steve Ranger, Global News Director
facebook-to-build-a-standalone-camera-app-similar-to-snapchat-one-touch-photo-and-video-sharing.jpg

Facebook says it has worked with Firefox and Chrome engineers on tweaks to their browsers that should make web pages download "dramatically" faster.

Over the past two years Facebook has been working with the Chrome and Firefox teams to improve browser caching. As a result, both have recently launched features that make their caches significantly more efficient for Facebook and the rest of the web.

Facebook's Ben Maurer and Nathan Schloss said the changes have helped reduce static resource requests to its servers by 60 percent and improved page load times as a result.

A static resource is a file that a server reads from disk and serves to the browser without running any extra code. Browsers often reuse things like logos or JavaScript code across different pages, and it's wasteful if browsers download them over and over again.

To prevent this, HTTP servers can specify an expiration time and a validator for each request. The expiration time tells the browser how long it can reuse the latest response for, and the validator allows the browser to continue to reuse the response even after the expiration time by allowing the browser to check with the server.

This raises other questions for web developers: how long should expiration times be? Too short and browsers will be checking in with servers too much; too long and browsers will be showing out-of-date information.

To get around this, Facebook uses the concept of 'content addressed URLs' so that its URLs are a hash of its content, which can then have a very long expiration time -- a year, for example. And because the contents of the URLs never change, Facebook's servers respond with a 304 not-modified response for any and all conditional requests for static resources, which saves on CPU cycles.

A 304 response is more efficient than downloading unneeded code, but it doesn't eliminate the latency of the browser talking to the server.

"Every time a not-modified response is sent, the browser already had the correct resource. We want to avoid these wasted revalidation by allowing the client to cache for longer," Facebook said.

Tweaking the browsers

But in 2014 Facebook found that 60 percent of requests for static resources resulted in a wasteful 304 response, and starting looking for ways to cut these down. It also noticed that there were substantial differences between the performance of different browsers: 63 percent of requests from Chrome were conditional, compared to 13 percent for Firefox, 14 percent from IE and 22 percent from Safari.

Facebook worked with Chrome's engineering team to fix the issue and Chrome's conditional requests dropped to 24 percent. Further tweaks saw the percent of Chrome conditional requests drop "dramatically" Facebook said.

In testing the Chrome team found that for mobile users with a 3G connection across all websites, reloading was 1.6 seconds faster with this change.

Facebook also worked with Firefox to add a new cache-control header for some resources in order to tell the browser that this resource should never be revalidated.

"Chrome and Firefox's measures have effectively eliminated revalidation requests to us from modern version of those browsers. This reduces traffic to our servers, but more importantly improves load time for people visiting Facebook," the company said.

Editorial standards