Most of my web career has been spent as a backend engineer. As such, I dutifully approached each performance project as an exercise in backend optimization, concentrating on compiler options, database indexes, memory management, etc. There's a lot of attention and many books devoted to optimizing performance in these areas, so that's where most people spend time looking for improvements. In reality, for most web pages, less than 10–20% of the end user response time is spent getting the HTML document from the web server to the browser. If you want to dramatically reduce the response times of your web pages, you have to focus on the other 80–90% of the end user experience. What is that 80–90% spent on? How can it be reduced? The chapters that follow lay the groundwork for understanding today's web pages and provide 14 rules for making them faster.
In order to know what to improve, we need to know where the user
spends her time waiting. Figure 1-1 shows the HTTP traffic when
Yahoo!'s home page (http://www.yahoo.com) is
downloaded using Internet Explorer. Each bar is one HTTP request. The
first bar, labeled html
, is the
initial request for the HTML document. The browser parses the HTML and
starts downloading the components in the page. In this case, the
browser's cache was empty, so all of the components had to be
downloaded. The HTML document is only 5% of the total response time. The
user spends most of the other 95% waiting for the components to
download; she also spends a small amount of time waiting for HTML,
scripts, and stylesheets to be parsed, as shown by the blank gaps
between downloads.
Figure 1-2 shows the same URL downloaded in Internet Explorer a second time. The HTML document is only 12% of the total response time. Most of the components don't have to be downloaded because they're already in the browser's cache.
Five components are requested in this second page view:
- One redirect
This redirect was downloaded previously, but the browser is requesting it again. The HTTP response's status code is 302 ("Found" or "moved temporarily") and there is no caching information in the response headers, so the browser can't cache the response. I'll discuss HTTP in Chapter 2.
- Three uncached images
The next three requests are for images that were not downloaded in the initial page view. These are images for news photos and ads that change frequently.
- One cached image
The last HTTP request is a conditional GETrequest. The image is cached, but because of the HTTP response headers, the browser has to check that the image is up-to-date before showing it to the user. Conditional GET requests are also described in Chapter 2.
Get High Performance Web Sites now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.