How Do Web Browsers Work

Have you ever wondered how a browser is capable of displaying visually attractive and interactive web pages? Have you encountered Error 404 or a DNS resolution error when trying to access a website? To answer these questions, let us examine the operating principles of browsers.

Browser Categories

Modern browsers can be classified into the following six categories, based on their kernels:

Kernel Browser
Trident IE
EDGE Microsoft Edge
Gecko Firefox
WebKit Safari, Chrome
Blink Chrome (newest release)
Presto Opera

Among these kernels, Trident, Gecko, Webkit, and Presto have been in use for many years. With the rapid advancement of browser technologies, many browsers have adopted newer kernels. Microsoft's newest browser, Edge, has replaced the IE browser, sending the Trident kernel to its end. Google has also begun to replace Webkit with newer Blink kernel on newer versions of the Chrome browser. In addition, Opera announced a technical shift to the Blink kernel, indicating that older kernel technologies are phasing out.

Despite these changes, the components of browsers and the principles of loading web pages in browsers are still similar. The figure below shows the major components of a browser:

Loading Sequence of a Browser

Once you enter a URL (for example, http://cloudcare.cn) in the address bar of a browser and press Enter, how does the browser load the corresponding web page?

The answer is through DNS lookup. After you press Enter, the browser has no idea what cloudcare.cn means. Furthermore, it does not know where the website with this domain name resides. In this case, a domain name server (DNS) translates the domain name into an IP address and directs the browser to the corresponding web page.

Suppose that the IP address of the local DNS server is 223.5.5.5.

The steps of accessing the website are as follows:
1. The browser sends a request to the DNS server for the address of cloudcare.cn.
2. The DNS server returns the IP address of the server that is hosting cloudcare.cn. In this example, the IP address is 10.0.0.1.
3. The local computer caches the DNS data and sends an access request for cloudcare.cn to the server with the IP address 10.0.0.1.
4. The server establishes a TCP connection with the local computer to exchange data.

TCP connection and HTTP

Once the TCP connection is set up, data transfer is ready. To transfer data, the connection must meet the requirements of the HTTP protocol (with versions 1.0 and 1.1), including connection, messaging, request and response rules.

Loading a single web page involves several hundreds of HTTP requests. The image below shows a typical structure of an HTTP header:

The corresponding header of a responded HTTP request is as follows:

Sometimes, the HTTP connection fails, and status codes such as 404 will be displayed instead.

Among the factors of an HTTP response, you may be most concerned with the response body. The following shows a simple response body.

This page looks familiar to most of us. Why? Well, this is the prepared HTML page code. With the HTML page code, we can know all the content contained on the website. But how does a browser render the HTML code into an interactive web page?

HTML Code Structure

Let us examine the structure of the HTML code. A complete HTML code consists of html, head, and body tags.

<html>
<head>
</head>
<body>
</body>
</html>

The head tag defines the header of the code, which can reference scripts, specify the style sheet, and provide prime information. However, the items defined here will not be displayed on the web page.

The body tag defines the elements and layout that the web page needs to present. Any written or visual content for the web page is placed within the body section.

Rendering process of an HTML page

The following describes the rendering process of a browser.

The HTML page for the homepage of cloudcare.cn is as follows:

Initially, a browser fetches page data from the server, which is called the base document, as shown in the figure above. Then, the browser converts the base document to a structured object named DOM tree and stores it in memory. Finally, the browser renders elements in the DOM tree as visual items according to the tree.

During the rendering, the browser renders the DOM tree from top to bottom and initiates HTTP requests once it detects external resources or scripts (such as the link, script and img tags in the figure above). Meanwhile, the browser will continue to parse the code:
1. The web page displays the "Hello world" string.
2. The page loads and displays images.
3. If you have defined a style that is similar to "div {color: red;}" in the style sheet, the page will display the "Hello world" string in red once it has fully loaded the style sheet.

Normally, this process is instantaneous and not visible to the user. However, when the connection is poor, you might be able to see the webpage develop based on the previously described sequence.

HTTP Cookies

Now, let us discuss cookies. Cookies are small but important pieces of data stored locally on a user's computer. A web browser then records information such as the user's web browsing activity on cookies. This information is useful for improving the user experience on a website but is also vulnerable to cyberattacks.

The HTTP protocol defines a list of operations on cookies. Ideally, the domain name that separates them from their storage is on the local computer in the location where we have the browser installed. Cookies have the following two key features:
1. They do not support cross-domain access (excluding child-level domains). For example, you cannot access any cookies under baidu.com from cloudcare.cn.
2. Each HTTP request will automatically carry cookies in the header before being sent to the backend server.

Conclusion

In this article, we looked at some of the basic operating principles of browsers. We discussed how a browser displays results for a search query and the loading sequence involved. We also looked at the HTML code structure and briefly discussed about cookies. To gain a more in-depth knowledge about web browsers, visit http://taligarsiel.com/Projects/howbrowserswork1.htm.

时间: 2024-10-19 07:06:00

How Do Web Browsers Work的相关文章

Web是开源最大的成功

  开源运动广受欢迎,并且在软件开发史上写下了浓重一笔.但是它影响最深远的地方在哪呢?有史以来,最成功的开源"项目"又是什么呢? 事实上,总体来看,Web不就是开源运动最大的成功么? 可能最有名的例子就是隐藏于众多网站背后的LAMP,也就是Linux.Apache.MySQL和PHP.但当你仔细考虑后,你会发现更多. 下面列出了Web得以运转的一些开源项目. Web browsers - 网络浏览器 在网络浏览器市场中,虽然微软的封闭源码软件IE浏览器仍然占有很大的份额,但其它功能相似

Programming Microsoft Office 2000 Web Components第一

第一章第二节 Office Web Components是什么? Office Web Components是一组的COM控件,设计的目的是为众多的控件容器提供交互的电子表格建模,数据报表和数据可视化功能.OWC库包含四个主要的组件:电子表格组件,图表组件,透视表组件和数据源组件.我们将在这一节中简要论述每个控件,然后在后续各章中讨论更多细节. 注释: COM也被称作ActiveX.当微软发明了术语"ActiveX"来描述COM技术时,我正在Visual Basic小组,这个术语使得我

Programming Microsoft Office 2000 Web Components第一章第一节

web 第一章第二节 Office Web Components是什么? Office Web Components是一组的COM控件,设计的目的是为众多的控件容器提供交互的电子表格建模,数据报表和数据可视化功能.OWC库包含四个主要的组件:电子表格组件,图表组件,透视表组件和数据源组件.我们将在这一节中简要论述每个控件,然后在后续各章中讨论更多细节. 注释: COM也被称作ActiveX.当微软发明了术语"ActiveX"来描述COM技术时,我正在Visual Basic小组,这个术

How browsers work

How browsers work ----- Behind the scenes of modern web browsers Introduction Web browsers are probably the most widely used software. In this book I will explain how they work behind the scenes. We will see what happens when you type 'google.com' in

现代浏览器客户端Web开发 Project Silk

MS Pattern & Practices http://www.microsoft.com/practices 团队发布了Silk项目和相关参考,为我们进入HTML5的开发世界提供了很好的参考.  Project Silk provides guidance for building maintainable cross-browser web applications that are characterized by an intentional design, rich interac

利用JSONP实现跨域请求

前言:有时候一忙起来就没了时间观念,原来我已经有十多天没写博客了.一直想做跨域方面的尝试,无奈最近准备校招没时间动动手.今天就先讲讲JSONP吧,昨晚还在研究QQ空间日志里面网络图片的问题呢,我发现日志还提供了HTML模式,我们可以利用img标签的src属性实现跨域请求,从自己的服务器里提取动态内容. JSONP 在讲实现之前,我们先来看看何为JSONP.以下是维基百科的解释: JSONP or "JSON with padding" is a communication techni

网页前端设计资源:前端设计资源收藏夹

文章简介:今天在邮件中收到一个由 Dimi Navrotskyy在Github上发布的前端收藏夹,里面的资源太丰富了.我在想很多同学肯定喜欢.本想直接发个链接与大家分享,但时间久了,找起来辛苦.特意copy了一份发在w3cplus上. 今天在邮件中收到一个由 Dimi Navrotskyy在Github上发布的前端收藏夹,里面的资源太丰富了.我在想很多同学肯定喜欢.本想直接发个链接与大家分享,但时间久了,找起来辛苦.特意copy了一份发在w3cplus上.而且我在后面还增加了一份我自己整理的学习

[引用] Taking a look at SWT Images

From: http://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html This first section of this article gives an introduction to colors and shows how an image records the color value of each pixel. Introduction Image lifecycle ImageData C

JavaScript:世界上误解最深的语言

javascript JavaScript, aka Mocha, aka LiveScript, aka JScript, aka ECMAScript, is one of the world's most popular programming languages. Virtually every personal computer in the world has at least one JavaScript interpreter installed on it and in act