How do web browsers work? | Web Demystified, Episode 5 – Transkript
Mozilla’s Web Demystified explains what modern browsers handle — networking, rendering, interactivity, storage and security — and walks through the rendering pipeline: requesting documents, parsing them into trees, computing layout and painting pixels, often 60 times a second.
Originalvideo von Mozilla Hacks auf YouTube. Bildunterschriften können Fehler enthalten; Überprüfen Sie die Zitate anhand der Aufzeichnung.
Wichtige Punkte
- Browsers handle network connections, including HTTP requests, two-way channels with servers and peer-to-peer connections.
- They parse and execute several languages and render fonts, images, audio and video, all of it interactive.
- They store data through caching and storage APIs, and sandbox content from different sources for security.
- Rendering works in four steps: request documents, parse them into internal trees, compute the page layout, then paint pixels.
- Because pages can change at any time, layout may be recomputed 30 to 60 times a second or more, a demand comparable to high-end games.
- Interactivity comes from native HTML and CSS behaviour and from JavaScript; knowing what triggers a new layout versus a repaint helps authors build faster pages.
Kapitel
Quelle und Lizenz
- Video
- How do web browsers work? | Web Demystified, Episode 5 · Mozilla Hacks
- Hochgeladen
- Lizenz
- Creative Commons Namensnennung (CC BY 3.0)
- Untertitel
- Von den Urhebern hochgeladene Untertitel
Kernpunkte und Kapitel werden von TranscriptYouTube anhand des Transkripts verfasst. Sie sind keine Faktenprüfung der Aussagen des Sprechers.
Videotranskript
How do web browsers work? | Web Demystified, Episode 5
- 0:00
Hello! Welcome to a new episode of Web Demystified.
- 0:03
In the previous episodes we talked about various web technologies at the heart of the web
- 0:08
and we've said that web browsers are mixing things together
- 0:11
in order to display web documents
- 0:13
Yeah, that really sounds like voodoo magic!
- 0:16
Really?
- 0:18
Okay, so today, let's talk a bit more about how browsers work and...
- 0:24
Let's kill the witchcraft.
- 0:34
Browsers are...
- 0:39
Browsers are very complex pieces of software that have drastically evolved since the 90's,
- 0:44
from rendering simple text to executing fully fledged applications.
- 0:49
So what are exactly browsers able to do these days?
- 0:54
First of all,
- 0:55
because the web is all about requesting documents stored on the Internet,
- 0:59
they are able to handle network connections.
- 1:02
Historically, that was done using the HTTP protocol
- 1:05
to perform simple CRUD operations on documents.
- 1:08
But nowadays they can also create bidirectional communication channels with a server
- 1:14
or they can even create a peer-to-peer connections with another browser.
- 1:17
Second, they have to be able to understand, render and/or execute different languages.
- 1:23
They also have to be able to render fonts, images, audio, and videos.
- 1:29
Third, everything you see in a browser must be interactive.
- 1:33
You can select text, scroll pages, click on links, input text, drag and drop content, etc.
- 1:41
Fourth, they can store data, either by caching content
- 1:45
or providing various storage mechanisms.
- 1:48
And all of this must work regardless of the complexity of each page
- 1:54
and regardless of the number of pages open at the same time!
- 1:58
This is…
- 2:00
very challenging
- 2:03
Last but not least, because the Internet remains a wild place
- 2:06
and because websites can aggregate contents from very different sources,
- 2:11
things have to be reasonably secured.
- 2:13
To do that browsers must be able to manage data encryption,
- 2:18
and to sandbox every set of contents
- 2:20
in order to prevent malicious code to access other contents,
- 2:23
or worse, your computer.
- 2:25
And this is just the tip of the iceberg.
- 2:29
So, let's try to keep things simple.
- 2:32
Okay, let's focus on the specific job of a browser, from a high level:
- 2:36
rendering multiple documents to display them to you in an interactive way.
- 2:41
Let’s start with the rendering.
- 2:42
One. The browser requests all the necessary documents
- 2:46
For the sake of example…
- 2:47
let's say we are requesting an HTML document
- 2:50
and its associated stylesheets and images.
- 2:53
Two. All documents will be parsed and turned into machine-friendly representations.
- 2:58
If you do a bit of research here, You'll hear fancy names like
- 3:02
DOM trees, Style trees, Rendering trees, Display lists
- 3:07
these are just different ways for browsers to represent documents.
- 3:11
Three. The intermediate representations are used to compute the whole page layout.
- 3:16
This is where the "mixing all the things" happen.
- 3:20
The browser computes the size, position, and representation
- 3:24
of everything that will be displayed on the page.
- 3:27
In the browser industry, senior engineers who are actually programing layout computations
- 3:31
are often considered true magicians because…
- 3:34
this is very likely one of the most complicated parts of a browser.
- 3:37
Four. The browser finally paints each element of the layout on the screen.
- 3:42
Tadda!
- 3:43
So to summarize:
- 3:45
the browser reads all the documents;
- 3:47
it turns them into several intermediate representations easier to use;
- 3:51
it computes the position of everything on the page;
- 3:54
and it paints each pixel accordingly.
- 3:57
Okay, this is roughly what any piece of software displaying content is doing.
- 4:03
The nuance comes from the interactive aspect of the web:
- 4:07
everything on a web page is dynamic,
- 4:10
meaning it can be changed or animated at will!
- 4:13
So if something is moving on the page,
- 4:18
the full layout must be recomputed at 30 or 60 frames per second, or even more
- 4:25
and regardless of the number of elements on the page.
- 4:29
Actually, the only other types of software that have to face such a challenge
- 4:36
are top of the line triple-A games.
- 4:38
Thanks to that, things can become interactive,
- 4:42
and there are two ways to handle interactivity:
- 4:45
On the one hand there are all the native interactions that the browser is providing,
- 4:50
usually through HTML and CSS.
- 4:53
Remember?
- 4:54
You can select text, scroll pages, click on links, input text, drag and drop content, etc.
- 5:02
On the other hand, there is what JavaScript lets people do.
- 5:06
Fundamentally, JavaScript lets people build any kind of interactivity
- 5:10
by granting them access to the core functionalities of the browsers.
- 5:14
You know, the one we've listed at the beginning of that video…
- 5:18
Yeah, OK, you get it!
- 5:19
The consequence of all of that is that
- 5:22
web authors must learn how browsers work
- 5:24
in order to optimize the experience they want to provide to their users.
- 5:28
For example it is a good idea to learn what triggers a new layout computation
- 5:33
versus a simple repaint, just because the latter is faster than the former.
- 5:38
Unfortunately, It’s hard to get into the details because…
- 5:41
each browser works somewhat differently.
- 5:43
Oh Thanks! That’s soooo helpful!
- 5:48
Well!
- 5:49
There are no big secrets and…
- 5:52
browser makers are working hard to make sure that
- 5:55
even the crappiest web pages are rendered fast and smooth.
- 5:58
But it's a topic for another video.
- 6:01
Okay, let's recap.
- 6:03
Browsers handle a lot of things:
- 6:06
networks, content display, data storage, content security…
- 6:11
all in a very interactive way.
- 6:12
They handle technical requirements
- 6:15
that can be compared to those of super high-end games.
- 6:18
And they give content creators the ability to create any form of interactivity.
- 6:23
Now you shouldn’t consider the web to be magic.
- 6:29
it’s just clever computer science.
- 6:32
Thank you all for watching this episode.
- 6:35
If you want to get into the nasty details of browser internal working,
- 6:39
I suggest that you have a look at this amazing talk by Tali Garsiel
- 6:43
In the meantime, if you enjoyed this episode
- 6:45
feel free to like it and to share it with your friends.
- 6:48
The more, the merrier!
- 6:49
To continue the discussion feel free to comment down below
- 6:51
or join me and my colleagues on Twitter.
- 6:53
And finally…
- 6:55
Long live the open web, see you next time!