Web page rendering process
11 March 2022 (Updated 15 March 2022)
Taken almost verbatim from Friendly Bit.
- You type a URL into your browser’s address bar.
- The browser parses the URL to find the protocol, host, port, and path (The different parts of a URL).
- It forms a HTTP request, assuming the URL begins with
http
(HTTP request format). - 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.
- Then a socket needs to be opened from the user’s computer to that IP number, on the port specified (most often port 80) (What is a TCP socket?).
- When a connection is open, the HTTP request is sent to the host.
- The host forwards the request to the server software (e.g., Nginx or Apache) configured to listen on the specified port.
- The server inspects the request (most often only the path), and launches a server plugin needed to handle the request (plugin will depend on programming language used on the server; examples include php-fpm for PHP or WSGI for Python).
- The plugin gets access to the full request, and starts to prepare a HTTP response.
- To construct the response a database may be accessed. A database search is made, based on parameters in the path (or data) of the request
- Data from the database, together with other information the plugin decides to add, is combined into a long string of text, typically HTML.
- The plugin combines that data with some meta data (in the form of HTTP headers), and sends the HTTP response back to the browser (HTTP response format).
- The browser receives the response, and parses the HTML in the response.
- A DOM tree is built out of the HTML.
- 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.
- Stylesheets are parsed, and the rendering information in each gets attached to the matching node in the DOM tree.
- Javascript is parsed and executed, and DOM nodes are moved and style information is updated accordingly
- The browser renders the page on the screen according to the DOM tree and the style information for each node.
- You see the page on the screen.
Sources
Tagged:
HTTP
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment