Skip to content

Instantly share code, notes, and snippets.

@abhinavnigam2207
Created February 19, 2019 06:52
Show Gist options
  • Save abhinavnigam2207/a3fb086fc3d85f77e0d385131e0e1ac2 to your computer and use it in GitHub Desktop.
Save abhinavnigam2207/a3fb086fc3d85f77e0d385131e0e1ac2 to your computer and use it in GitHub Desktop.
How browser renders a web page (Browsers Life cycle)
  1. You type an URL into address bar in your preferred browser.
  2. The browser parses the URL to find the protocol, host, port, and path and it forms a HTTP request (that was most likely the protocol).
  3. To reach the host, it first needs to translate the human readable host into an IP number, and it does this by doing a DNS lookup on the host
  4. Then a socket needs to be opened from the user’s computer to that IP number, on the port specified (most often port 80)
  5. When a connection is open, the HTTP request is sent to the host
  6. The host forwards the request to the server software (most often Apache) configured to listen on the specified port
  7. The server inspects the request (most often only the path), and launches the server plugin needed to handle the request (corresponding to the server language you use, PHP, Java, .NET, Python?)
  8. The plugin gets access to the full request, and starts to prepare a HTTP response.
  9. To construct the response a database is (most likely) accessed. A database search is made, based on parameters in the path (or data) of the request
  10. Data from the database, together with other information the plugin decides to add, is combined into a long string of text (probably HTML).
  11. The plugin combines that data with some meta data (in the form of HTTP headers), and sends the HTTP response back to the browser.
  12. The browser receives the response, and parses the HTML (which with 95% probability is broken) in the response.
  13. A DOM tree is built out of the broken HTML and new requests are made to the server for each new resource that is found in the HTML source (typically images, style sheets, and JavaScript files). Go back to step 3 and repeat for each resource.
  14. Stylesheets are parsed, and the rendering information in each gets attached to the matching node in the DOM tree.
  15. Javascript is parsed and executed, and DOM nodes are moved and style information is updated accordingly.
  16. The browser renders the page on the screen according to the DOM tree and the style information for each node and you see the page on the screen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment