2.5 Web Browsers

The user experience for a website is unlike the user experience for traditional desktop software. Users do not download software; they visit a URL, which results in a web page being displayed. Although a typical web developer might not build a browser, or develop a plugin, they must understand the browser’s crucial role in web development.

2.5.1 Fetching a web page

Although we as web users might be tempted to think of an entire page being returned in a single HTTP response, this is not in fact what happens.

In reality, the experience of seeing a single web page is facilitated by the client’s browser, which requests the initial HTML page, then parses the returned HTML to find all the resources referenced from within it, like images, style sheets, and scripts. Only when all the files have been retrieved is the page fully loaded for the user, as shown in Figure 2.15. A single web page can reference dozens of files and requires many HTTP requests and responses.

Figure 2.15 Browser parsing HTML and making subsequent requests

The figure illustrates the communication between them.

The fact that a single web page requires multiple resources, possibly from different domains, is the reality we must work with and be aware of. Modern browsers provide the developer with tools that can help us understand the HTTP traffic for a given page.

2.5.2 Browser Rendering

The algorithms within browsers to download, parse, layout, fetch assets, and create the final interactive page for the user are commonly referred to collectively as the rendering of the page and is a matter of great interest to web browser creators. This complex process is implemented differently for each browser and is one big reason that browsers format web pages differently, and load them with differing speeds.

While the mechanics and sequence of browser fetching, parsing, layout creation and Javascript parsing are interesting, we will focus on the browser-rendering process through a user-centric lens that provides a high-level framework to understand browser-rendering algorithms.

User-centric thinking measures how humans feel about things like delays and jumpy layouts, rather than measure precise things humans don’t care about like “how long until the DOM is loaded.” For this reason, human-centric measures are categorized around perceived loading performance, interactivity, and visual stability.

The perceived events that occur during the rendering process, depicted in Figure 2.16, are as follows:

Figure 2.16 Visualizing the key events in the rendering timeline for a website

The figure shows 8 Browser Windows that are placed side-by-side that illustrate the key events in rendering the timeline for a website.

It should be noted that the rendering process does not completely stop when the page is loaded, since the page must be redrawn in response to user events, such as clicks, scrolls, CSS hovers, and JavaScript processing. This makes browser rendering an ongoing area of improvement in all browsers, and a big reason modern tools exist to profile how your webpage is using resources. These rendering implementations not only differentiate browsers, but they provide the framework that you can use to analyze and improve your websites, as you will see later in Chapter 18.

2.5.3 Browser Caching

Once a webpage has been downloaded from the server, it’s possible that the user, a short time later, wants to see the same web page and refreshes the browser or re-requests the URL. Although some content might have changed (say a new blog post in the HTML), the majority of the referenced files are likely to be unchanged (i.e., “fresh” as illustrated in Figure 2.17), so they needn’t be redownloaded. Browser caching has a significant impact in reducing network traffic and will be come up again in greater detail throughout this book.

Figure 2.17 Illustration of browser caching, using cached resources

The figure illustrates the browser caching using cached resources.

2.5.4 Browser features

Once upon a time, browsers had very few features aside from the minimum requirements of displaying web pages, and perhaps managing bookmarks. Over the decades, users have come to expect more from browsers, so now they include features, such as search engine integration, URL autocompletion, cloud caching of user history/bookmarks, phishing website detection, secure connection visualization, and much more.

These features enhance the browsing experience for users, and require that web developers test their webpages before deployment to ensure none of these features change the performance of their webpage.

2.5.5 Browser Extensions

Browser extensions extend the basic functionality of the browser. They are written in JavaScript and offer value to both developers and the general public, though they complicate matters somewhat since they can occasionally interfere with the presentation of web content.

For developers, extensions such as Firebug and YSlow offer valuable debugging and analysis tools at no cost. These tools let us find bugs or analyze the speed of our site, integrating with the browser to provide access to lots of valuable information.

For the general public, extensions can add functionality, such as auto-fill forms and passwords. Ad-blocking extensions, such as AdBlock have improved the web experience by removing intrusive ads for users but have reduced revenue and challenged current business models for webmasters relying on ad displays.