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

后端 未结 4 499
别那么骄傲
别那么骄傲 2021-01-30 07:44

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 understandi

相关标签:
4条回答
  • 2021-01-30 08:02

    I can describe one point here -

    Determining which file/resource to execute, which language interpreter to load.

    Pardon me if I am wrong in using interpreter here. There may be other mistakes in my answer, I will try to correct them later and include proper technical terms for things.

    When the web server (e.g. apache) has received the URI it checks if there is any existing rewrite rule matching it. In that case the rewritten URI is taken. In either case, if there is no file name to end the URI, the default file is loaded, which is generally index.html or index.php etc. According to the extension of the file name, the appropriate apache module for server-side programming language support is loaded, e.g. mod_php for PHP, mod_python in case of python. The appropriate server side language interpreter (considering interpreted languages like PHP) then prepares the final HTML or output in some other form for the web server which finally sends it as the HTTP response.

    0 讨论(0)
  • 2021-01-30 08:15

    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?

    0 讨论(0)
  • 2021-01-30 08:15
    1. You type maps.google.com(Uniform Resource Locator) into the address bar of your browser and press enter.
    2. Every URL has a unique IP address associated with it. The mapping is stored in Name Servers and this procedure is called Domain Name System.
    3. The browser checks its cache to find the IP Address for the URL.
      • If it doesn't find it, it checks its OS to find the IP address (gethostname);
      • It then Checks the router's cache.
      • It then checks the ISP's cache. If it is not available there the ISP makes a recursive request to different name servers.
    4. It Checks the com name server (we have many name servers such as 'in', 'mil', 'us' etc) and it will redirect to google.com
    5. google.com name server will find the matching IP address for maps.google.com in its’ DNS records and return it to your DNS recursor which will send it back to your browser.
    6. Browser initiates a TCP connection with the server.It uses a three way handshake

      • Client machine sends a SYN packet to the server over the internet asking if it is open for new connections.

      • If the server has open ports that can accept and initiate new connections, it’ll respond with an ACKnowledgment of the SYN packet using a SYN/ACK packet.

      • The client will receive the SYN/ACK packet from the server and will acknowledge it by sending an ACK packet. Then a TCP connection is established for data transmission!

    7. The browser will send a GET request asking for maps.google.com web page. If you’re entering credentials or submitting a form this could be a POST request.
    8. The server sends the response.
    9. Once the server supplies the resources (HTML, CSS, JS, images, etc.) to the browser it undergoes the below process:
      Parsing - HTML, CSS, JS
      Rendering - Construct DOM Tree → Render Tree → Layout of Render Tree → Painting the render tree
    10. The rendering engine starts getting the contents of the requested document from the networking layer. This will usually be done in 8kB chunks.
    11. A DOM tree is built out of the broken response.
    12. 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).
    13. At this stage the browser marks the document as interactive and starts parsing scripts that are in "deferred" mode: those that should be executed after the document is parsed. The document state is set to "complete" and a "load" event is fired.
    14. Each CSS file is parsed into a StyleSheet object, where each object contains CSS rules with selectors and objects corresponding CSS grammar. The tree built is called CSSCOM.
    15. On top of DOM and CSSOM, a rendering tree is created, which is a set of objects to be rendered. Each of the rendering objects contains its corresponding DOM object (or a text block) plus the calculated styles. In other words, the render tree describes the visual representation of a DOM.
    16. After the construction of the render tree it goes through a "layout" process. This means giving each node the exact coordinates where it should appear on the screen.
    17. The next stage is painting–the render tree will be traversed and each node will be painted using the UI backend layer.
    18. Repaint: When changing element styles which don't affect the element's position on a page (such as background-color, border-color, visibility), the browser just repaints the element again with the new styles applied (that means a "repaint" or "restyle" is happening).
    19. Reflow: When the changes affect document contents or structure, or element position, a reflow (or relayout) happens.
    0 讨论(0)
  • 2021-01-30 08:25

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

    0 讨论(0)
提交回复
热议问题