Wednesday, 16 November 2016

What happens (Steps) when an URL is requested from address bar in Browser.(Eg.www.facebook.com)

Steps-
Suppose we type www.facebook.com in address bar of browser.

Whenever we want to connect to "facebook", we want to reach to the server where google web service is hosted. Each host name (facebook.com) has IP associated with it.
Eg. Say www.facebook.com has IP of 74.125.236.65.
        If we type http://www.facebook.com or http://74.125.236.65 we expect facebook server to show homepage. But both addresses may not be same.
But in real scenario facebook has multiple servers at multiple locations to cater huge volume of request they get per second. Hence we should let facebook decide which server is best for my response. Hence using host name solves the problem of typing actual facebook server IP.
        
              DNS (Domain Name System) resolves the problem of mapping URL with IP.
  
  1. First browser checks DNS records in its own cache for IP of requested server.
  If not found ,
  2. Browser checks DNS records in OS cache for IP of requested server.
  if not found,
  It decides to contact ISP.
  3. A request is sent to DNS server, that has the database of IP address and Host Names.
      DNS server tries to identify IP address for queried hostname.(It searches in DNS hierarchy until topmost DNS server).If found the requested IP , It is returned. Otherwise server not found message is sent.
 4. Since browser knows IP of server to contacted, Now browser initiates a TCP connection with server.
 5. Browser assembles http request which consists of header and optional content. 
     Request header has below content -

    
Where,
GET - http request type (always GET)
Accept - http response type expected
User Agent - Browser details
Connection - Asks connection server to keep TCP connection established for response.
Host - Host Name
Cookie - sent server cookie for previous browser session. Cookie has map with KV for user and Facebook

6. Browser receives the response in return.




where,
OK - http response status.
Content Type
Connection -asks browser to keep TCP connection open
Content -length - No of bytes

7. Browser renders HTML content.
    HTML rendering is also done in phases.
    7.1 - First HTML bare bone structure.
    7.2 - Then sends multiple GET request to get resources like images, JavaScript files, CSS files for HTML rendering.
   Now these images will be stored in the browser cache, so that next time it does not have to send    GET request to server for HTML rendering resources.
     







































No comments:

Post a Comment