Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the complete process from entering a url to the browser's address bar to get the rendered page in browser?

I'm thinking about this question for a long time. It is a big question, since it almost covers all corners related to web developing.

In my understanding, the process should be like:

  1. enter the url to the address bar
  2. a request will be sent to the DNS server based on your network configuration
  3. DNS will route you to the real IP of the domain name
  4. a request(with complete Http header) will be sent to the server(with 3's IP to identify)'s 80 port(suppose we don't specify another port)
  5. server will search the listening ports and forward the request to the app which is listening to 80 port(let's say nginx here) or to another server(then 3's server will be like a load balancer)
  6. nginx will try to match the url to its configuration and serve as an static page directly, or invoke the corresponding script intepreter(e.g PHP/Python) or other app to get the dynamic content(with DB query, or other logics)
  7. a html will be sent back to browser with a complete Http response header
  8. browser will parse the DOM of html using its parser
  9. external resources(JS/CSS/images/flash/videos..) will be requested in sequence(or not?)
  10. for JS, it will be executed by JS engine
  11. for CSS, it will be rendered by CSS engine and HTML's display will be adjusted based on the CSS(also in sequence or not?)
  12. if there's an iframe in the DOM, then a separate same process will be executed from step 1-12

The above is my understanding, but I don't know whether it's correct or not? How much precise? Did I miss something?

If it's correct(or almost correct), I hope:

  1. Make the step's description more precise in your words, or write your steps if there is a big change
  2. Make a deep explanation for each step which you are most familiar with.
  3. One answer per step. Others can make supplement in each answer's comment.

And I hope this thread can help all web developers to have a better understanding about what we do everyday.

And I will update this question based on the answers.

Thanks.

like image 538
Zhu Tao Avatar asked Mar 02 '11 09:03

Zhu Tao


People also ask

How do you enter a URL into your browser?

Using the Address Bar. Find the address bar. This is usually a long white bar at the top of your browser window. You will type the web address into this bar (with the correct form), then hit ↵ Enter in order to visit the website.

How a web page is rendered by a browser?

A simple text and image are rendered on the screen. From previous explanations, the browser reads raw bytes of the HTML file from the disk (or network) and transforms that into characters. The characters are further parsed into tokens. As soon as the parser reaches the line with <link rel="stylesheet" href="style.


2 Answers

As you say this is a broad question where it's possible to go into great detail on a number of topics. There's nothing wrong with the sequence you described, but you're leaving out a lot of detail. To mention a few:

  • The DNS layer can help direct clients to different servers based on geographical location to help with load balancing and latency minimization, and one server can respond to requests from many different DNS names.
  • A browser can make different types of requests (GET, POST, HEAD, etc), and usually includes several different headers including cookies, browser capabilities, language preferences, etc.
  • Most browsers usually maintain a cache in order to avoid downloading stuff many times, and use various techniques to determine whether the cached version of a file is valid.
  • In modern webpages there's often complex interaction between many different kinds of files (HTML, CSS, images, JavaScript, video, Flash, ...), and web developers often need detailed knowledge of differences among browsers in order to keep their pages working for everyone

Each of these topics, and many more, could be discussed at length. Perhaps it's more practical to ask more specific questions about the topics you're interested in?

like image 123
Nico Avatar answered Oct 21 '22 00:10

Nico


i was also searching for the same thing and found this awesome detailed answer being built collaboratively at github

like image 40
Shiva Ramaseshan Avatar answered Oct 21 '22 01:10

Shiva Ramaseshan