Skip to Content
High Performance Images
book

High Performance Images

by Colin Bendell, Tim Kadlec, Yoav Weiss, Guy Podjarny, Nick Doyle, Mike McCall
November 2016
Intermediate to advanced
354 pages
8h 39m
English
O'Reilly Media, Inc.
Content preview from High Performance Images

Chapter 7. Browser Image Loading

Before we discuss image delivery, we should discuss how browsers load images. We’ll cover several performance best practices as we do so, but this chapter will serve primarily as a foundation for advice in later chapters.

Referencing Images

The primary two ways a web page can load an image are:

  • An HTML <img> tag

  • A CSS background-image

Both techniques will trigger the download and display of an image, but each has some important unique characteristics, which we’ll explain next.

It’s worth noting there are several newer ways to load images, focusing on the “responsive images” practice of downloading images sized appropriately to the current display. These include the image-set CSS property, <picture> element, and srcset attribute, all of which will be discussed in Chapter 11.

JavaScript Image Object

Another often-used technique to load an image is using the JavaScript new Image() constructor. While this constructor is standardized and widely supported, it’s actually just another way to create an HTMLImageElement, and is functionally equivalent to document.createElement("img").

<img> tag

The simplest way to load an image is to use the HTML <img> tag. This tag requires only a single src attribute (which points to the image location), and doesn’t even need to be closed (see Example 7-1 and Figure 7-1).

Example 7-1. Simple <img> tag
<img src="book.jpg">
Figure 7-1. Result of Example 7-1

The full <img> tag supports ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Optimizing images

Optimizing images

Lara Callender Hogan
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
Responsive & Fast

Responsive & Fast

Guy Podjarny
Image Processing and Acquisition using Python, 2nd Edition

Image Processing and Acquisition using Python, 2nd Edition

Ravishankar Chityala, Sridevi Pudipeddi

Publisher Resources

ISBN: 9781491925799Errata Page