How WebKit Loads a Web Page

转载 2011年01月13日 13:39:00

How WebKit Loads a Web Page

Posted by abarth on Sunday, April 18th, 2010 at 1:57 pm

Before WebKit can render a web page, it needs to load the page and all of its subresources from the network. There are many layers involved in loading resources from the web. In this post, I’ll focus on explaining how WebCore, the main rendering component of WebKit, is involved in the loading process.

WebKit contains two loading pipelines, one for loading documents into frames and another for loading the subresources (such as images and scripts). The diagram below summarizes the major objects involved in the two pipelines:


Loading Frames

The FrameLoader is in charge of loading documents into Frames. Whenever you click a link, the FrameLoader begins by creating a new DocumentLoader object in the “policy” state, where it awaits a decision by the WebKit client about how it should handle this load. Typically, the client will instruct the FrameLoader to treat the load as a navigation (instead of blocking the load, for example).

Once the client instructs the FrameLoader to treat the load as a navigation, the FrameLoader advances the DocumentLoader to the “provisional” state, which kicks off a network request and waits to determine whether the network request will result in a download or a new document.

The DocumentLoader, in turn, creates a MainResourceLoader, whose job is to interact with the platform’s network library via the ResourceHandle interface. Separating the MainResourceLoader from DocumentLoader serves two purposes: (1) the MainResourceLoader insulates the DocumentLoader from details of handling the callbacks from the ResourceHandle and (2) the lifetime of the MainResourceLoader is decoupled from the lifetime of the DocumentLoader (which is tied to the Document).

Once the loading system has received sufficient information from the network to determine that the resource actually represents a document, the FrameLoader advances the DocumentLoader to the “committed” state, which transitions the Frame to displaying the new document.

Loading Subresources

Of course, displaying a web page requires more than just the HTML that comprises the document. We also need to load the images, scripts, and other subresources referenced by the document. The DocLoader is in charge of loading these subresources. (Note that although DocumentLoader and DocLoader have similar names, their roles are quite different.)

Let’s take loading an image as a typical example. To load an image, the DocLoader first asks the Cache whether it already has a copy of the image in memory (as a CachedImage object). If the image is already in the Cache, the DocLoader can respond immediately with the image. For even greater efficiency, the Cache often keeps the decoded image in video memory so that WebKit does not have to uncompress the same image twice.

If the image is not in the Cache, the Cache creates a new CachedImage object to represent the image. The CachedImage object asks the “Loader” object to kick off a network request, which the Loader does by creating a SubresourceLoader. The SubresourceLoader plays a similar role in the subresource loading pipeline as the MainResourceLoader does in the main resource loading pipeline in that it interacts most directly with the ResourceHandle interface to the platform.

Areas for Improvement

There are many areas in which we can improve WebKit’s loading pipelines. The FrameLoader is significantly more complex than necessary and encompasses more tasks than simply loading a frame. For example, FrameLoader has a several subtly different methods named “load,” which can be confusing, and is responsible for creating new windows, which seems only tangentially related to loading a frame. Also, the various stages of the loading pipeline are more tightly coupled than necessary and there are a number of “layering” violations in which a lower-level object interacts directly with a higher-level object. For example, the MainResourceLoader delivers bytes received from the network directly to FrameLoader instead of delivering them to DocumentLoader.

If you study the diagram above, you will notice that the Cache is used only for subresources. In particular, main resource loads do not get the benefits of WebKit’s memory cache. If we can unify these two loading pipelines, we might be able to improve the performance of main resource loads. Over time, we hope to improve the performance of the loader to make loading web pages as fast as possible.

原文地址: http://webkit.org/blog/1188/how-webkit-loads-a-web-page/

关于 iOS 10 中 ATS 的问题

WWDC 15 提出的 ATS (App Transport Security) 是 Apple 在推进网络通讯安全的一个重要方式。在 iOS 9 和 OS X 10.11 中,默认情况下非 HTTP...
  • u012947646
  • u012947646
  • 2016年07月15日 11:11
  • 8273

WebKit(展示Web界面)

WKWebView
  • y550918116j
  • y550918116j
  • 2015年11月30日 15:29
  • 1464

开发者应当了解的WebKit知识

对一些开发者而言,WebKit就是一个黑盒子。丢进去HTML、CSS、JS等一连串的东西,而WebKit就能变魔术一般显示出一个很棒的网页出来。实际上,正我的同事IlyaGroriks提到的:   ...
  • HorkyChen
  • HorkyChen
  • 2013年03月02日 22:46
  • 60685

webkit Page对象的分析

原帖地址:http://blog.csdn.net/shunzi__1984/article/details/6243767
  • jiangnanyidiao
  • jiangnanyidiao
  • 2014年11月03日 16:23
  • 556

webkit page对象分析

http://blog.csdn.net/shunzi__1984/article/details/6243767 webkit Page对象的分析     Page对象是webkit的...
  • liumf2005
  • liumf2005
  • 2013年04月24日 23:13
  • 458

如何优化运行在webkit上的web app

近来公司有个web app 项目运行在移动版android系统上,发现在电脑上跑的很流畅的web页面在移动版webkit上非常不流畅。根本无法和native app相媲美。HTML5的性能还真是让人纠...
  • talking12391239
  • talking12391239
  • 2014年01月21日 14:42
  • 2267

WebKit焦点切换的流程

WebKit的焦点切换与Tab事件关联,点击Tab键后,WebKit内核会将焦点切换到下一个焦点. 一. Tab事件的处理     Tab事件在keydown阶段处理,内核处理的入口是EventHan...
  • skyhacer
  • skyhacer
  • 2013年04月25日 08:30
  • 2199

Python下json.loads()中文字符出错解决

使用json.load()时,中文字符被转化为Unicode码的问题
  • MrLevo520
  • MrLevo520
  • 2016年06月14日 18:12
  • 4231

python json loads遇到中文的情况分析。

python中自带了处理python的模块,使用时候直接import json即可。 使用loads方法即可将json字符串转换成python对象,对应关系如下: JSON...
  • chenzy945
  • chenzy945
  • 2014年01月14日 17:26
  • 9042

QT之QtWebKit与JavaScript交互(一)

QT之QtWebKit与JavaScript交互(一)     最近一个GIS的项目涉及到QtWebKit以及与JavaScript的交互,所以就看来很多材料,关于QtWebKit的理论网上很多,但...
  • zhangbinsijifeng
  • zhangbinsijifeng
  • 2016年05月25日 14:42
  • 827
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How WebKit Loads a Web Page
举报原因:
原因补充:

(最多只允许输入30个字)