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

Operating_Principles_of_Browsers

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:

01

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.

02

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:

03

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

04

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.

05

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:

06

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.

目录
相关文章
|
Web App开发 前端开发 .NET
Do You Kown Asp.Net Core -- Asp.Net Core 2.0 未来web开发新趋势 Razor Page
Razor Page介绍 前言     上周期待已久的Asp.Net Core 2.0提前发布了,一下子Net圈热闹了起来,2.0带来了很多新的特性和新的功能,其中Razor Page引起我的关注,作为web程序员来说,Asp.Net下的任何web框架都会去特别关注,因为每次一个新的框架出来,意味着一次革命。
1638 0
|
3月前
|
XML JSON API
ServiceStack:不仅仅是一个高性能Web API和微服务框架,更是一站式解决方案——深入解析其多协议支持及简便开发流程,带您体验前所未有的.NET开发效率革命
【10月更文挑战第9天】ServiceStack 是一个高性能的 Web API 和微服务框架,支持 JSON、XML、CSV 等多种数据格式。它简化了 .NET 应用的开发流程,提供了直观的 RESTful 服务构建方式。ServiceStack 支持高并发请求和复杂业务逻辑,安装简单,通过 NuGet 包管理器即可快速集成。示例代码展示了如何创建一个返回当前日期的简单服务,包括定义请求和响应 DTO、实现服务逻辑、配置路由和宿主。ServiceStack 还支持 WebSocket、SignalR 等实时通信协议,具备自动验证、自动过滤器等丰富功能,适合快速搭建高性能、可扩展的服务端应用。
213 3
|
1月前
|
前端开发 安全 JavaScript
2025年,Web3开发学习路线全指南
本文提供了一条针对Dapp应用开发的学习路线,涵盖了Web3领域的重要技术栈,如区块链基础、以太坊技术、Solidity编程、智能合约开发及安全、web3.js和ethers.js库的使用、Truffle框架等。文章首先分析了国内区块链企业的技术需求,随后详细介绍了每个技术点的学习资源和方法,旨在帮助初学者系统地掌握Dapp开发所需的知识和技能。
2025年,Web3开发学习路线全指南
|
2月前
|
设计模式 前端开发 数据库
Python Web开发:Django框架下的全栈开发实战
【10月更文挑战第27天】本文介绍了Django框架在Python Web开发中的应用,涵盖了Django与Flask等框架的比较、项目结构、模型、视图、模板和URL配置等内容,并展示了实际代码示例,帮助读者快速掌握Django全栈开发的核心技术。
232 45
|
2月前
|
存储 前端开发 JavaScript
如何在项目中高效地进行 Web 组件化开发
高效地进行 Web 组件化开发需要从多个方面入手,通过明确目标、合理规划、规范开发、加强测试等一系列措施,实现组件的高效管理和利用,从而提高项目的整体开发效率和质量,为用户提供更好的体验。
44 7
|
2月前
|
开发框架 搜索推荐 数据可视化
Django框架适合开发哪种类型的Web应用程序?
Django 框架凭借其强大的功能、稳定性和可扩展性,几乎可以适应各种类型的 Web 应用程序开发需求。无论是简单的网站还是复杂的企业级系统,Django 都能提供可靠的支持,帮助开发者快速构建高质量的应用。同时,其活跃的社区和丰富的资源也为开发者在项目实施过程中提供了有力的保障。
|
2月前
|
开发框架 JavaScript 前端开发
TypeScript 是一种静态类型的编程语言,它扩展了 JavaScript,为 Web 开发带来了强大的类型系统、组件化开发支持、与主流框架的无缝集成、大型项目管理能力和提升开发体验等多方面优势
TypeScript 是一种静态类型的编程语言,它扩展了 JavaScript,为 Web 开发带来了强大的类型系统、组件化开发支持、与主流框架的无缝集成、大型项目管理能力和提升开发体验等多方面优势。通过明确的类型定义,TypeScript 能够在编码阶段发现潜在错误,提高代码质量;支持组件的清晰定义与复用,增强代码的可维护性;与 React、Vue 等框架结合,提供更佳的开发体验;适用于大型项目,优化代码结构和性能。随着 Web 技术的发展,TypeScript 的应用前景广阔,将继续引领 Web 开发的新趋势。
52 2
|
2月前
|
前端开发 API 开发者
Python Web开发者必看!AJAX、Fetch API实战技巧,让前后端交互如丝般顺滑!
在Web开发中,前后端的高效交互是提升用户体验的关键。本文通过一个基于Flask框架的博客系统实战案例,详细介绍了如何使用AJAX和Fetch API实现不刷新页面查看评论的功能。从后端路由设置到前端请求处理,全面展示了这两种技术的应用技巧,帮助Python Web开发者提升项目质量和开发效率。
68 1
|
2月前
|
XML 安全 PHP
PHP与SOAP Web服务开发:基础与进阶教程
本文介绍了PHP与SOAP Web服务的基础和进阶知识,涵盖SOAP的基本概念、PHP中的SoapServer和SoapClient类的使用方法,以及服务端和客户端的开发示例。此外,还探讨了安全性、性能优化等高级主题,帮助开发者掌握更高效的Web服务开发技巧。
|
2月前
|
安全 数据库 开发者
Python Web开发:Django框架下的全栈开发实战
【10月更文挑战第26天】本文详细介绍了如何在Django框架下进行全栈开发,包括环境安装与配置、创建项目和应用、定义模型类、运行数据库迁移、创建视图和URL映射、编写模板以及启动开发服务器等步骤,并通过示例代码展示了具体实现过程。
87 2