Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

How Facebook load images so fast ??

Wondering about how Facebook load images very fast and also use less data ? Check out this article to know more !

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
According to a report by Facebook community, At the very beginning Facebook was struct in loading images slow as other sites. This resulted in a massive loss of visitors and many of the people where migrating to different social websites. To stop this Facebook came with a new technology where it used less data and also loaded images very fast.
Now the questions is how images are loaded fast ? What was that technology? 
Facebook's Technique :
 The first thing facebook done is they compressed the background image by using various tools.
Secondly Facebook added a code in its database on which before any actually load of the original image a low-resolution variant of the original image is loaded thus visitor see blured image in just miliseconds and may opt on a wait for full resolution.
Facebook reduced the resolution of the image from 9864x5492 pixels to 30x12 pixels. This results in an image size less than equal to 900 bytes.
Now the problem was a low-resolution blurred image as a background. To solve this Facebook first load the images in the low-resolution and already load the high-resolution image asynchronous in the background. Once the high-resolution image is loaded then theh low resolution is changed with the high -resolution image. To accomplish this Facebook used the following javascript loaded in before the end body tag. This way the script does not render-blocking other page content.
Javascript code used for loading images fast :-

 (() => { 'use strict'; // Page is loaded const objects = document.getElementsByClassName('asyncImage'); Array.from(objects).map((item) => { // Start loading image const img = new Image(); img.src = item.dataset.src; // Once image is loaded replace the src of the HTML element img.onload = () => { item.classList.remove('asyncImage'); return item.nodeName === 'IMG' ? item.src = item.dataset.src : item.style.backgroundImage = `url(${item.dataset.src})`; }; }); })(); 
(Originally by Facebook) 
This code is assigned at the last. Using this type of code Facebook started to browse the images fast and due to this user experience good.
For more articles on technical topics subscribe to us only on Www.newsandstory.com 


CONTINUE READING
Facebook
load
image
fast
Javascript
coding
Technology
Dalpat I
Content writer