Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
45 views
in Technique[技术] by (71.8m points)

javascript - Describe the page rendering process in a browser?

First of all, I am not interested in the entire request-response process as addressed by this question

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

I want to know what goes on inside a browser, once it receives the html response from the server. The intent behind asking this question is to understand the inner details of client side scripting. Also it would be beneficial if you can explain in abstract concepts what a web browser comprises of. You may call them as CSS engine, javascript engine etc.The goal is to precisely visualize the web development I am doing.

Unfortunately, I did not find any web resources addressing this issue. Please forgive me if there are resources out there which explain these concepts. You may point to the resources (books, etc) if this question is too exhaustive to answer.

question from:https://stackoverflow.com/questions/7515227/describe-the-page-rendering-process-in-a-browser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please go through below steps and you should be clear with request lifecycle and how response is rendered.

  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.

  3. It forms a HTTP request (that was most likely the protocol)

  4. 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

  5. Then a socket needs to be opened from the user’s computer to that IP number, on the port specified (most often port 80)

  6. When a connection is open, the HTTP request is sent to the host 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

  14. 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).

  15. Go back to step 3 and repeat for each resource.

  16. Stylesheets are parsed, and the rendering information in each gets attached to the matching node in the DOM tree

  17. JavaScript is parsed and executed, and DOM nodes are moved and style information is updated accordingly

  18. The browser renders the page on the screen according to the DOM tree and the style information for each node

  19. You see the page on the screen

  20. You get annoyed the whole process was too slow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...