How Safari's Lazy Loading Reduces Load Time and Bandwidth
This article explores how implementing the
loading="lazy" HTML attribute on images and iframes
significantly improves web performance in the Safari web browser. By
deferring the downloading of off-screen media until a user scrolls near
them, Safari reduces initial page load times and conserves valuable
bandwidth. Below is a straightforward breakdown of how Safari’s WebKit
engine handles native lazy loading, eliminates network contention, and
optimizes both data usage and rendering speed.
How Safari
Processes the loading="lazy" Attribute
Normally, when Safari loads a webpage, its WebKit engine parses the HTML and immediately begins fetching every image and iframe it encounters, regardless of whether those elements are visible to the user.
When you add the loading="lazy" attribute to an
<img> or <iframe> tag, you
instruct Safari to pause the network request for that specific resource
if it is located below the fold (outside the user's current screen
view). Instead of downloading the media immediately, Safari places a
lightweight internal Intersection Observer on the element. The browser
only initiates the download when the user scrolls down and the element
approaches a specific distance threshold from the viewport.
Reducing Initial Page Load Time
Lazy loading directly accelerates the initial page load time in Safari through three main mechanisms:
- Eliminating Network Contention: Bandwidth is finite. When Safari tries to download dozens of off-screen images and iframes at once, those files compete for network resources with critical files like CSS, fonts, and JavaScript. By deferring off-screen media, Safari allocates 100% of the available network connection to downloading and rendering the visible, above-the-fold content first.
- Freeing Up the Main Thread: Loading an
<iframe>—such as an embedded YouTube video or a third-party map—is essentially loading an entire secondary webpage. It requires Safari to parse additional HTML, execute heavy JavaScript, and style new elements. Deferring iframes prevents this background processing from blocking Safari’s main thread, allowing the main page to become interactive much faster. - Faster
loadEvent Firing: Because Safari does not have to wait for deferred images and iframes to finish downloading, the browser reaches its final loaded state much faster. This improves core web vitals, specifically Largest Contentful Paint (LCP) and First Input Delay (FID).
Conserving Bandwidth
The bandwidth savings provided by loading="lazy" in
Safari are directly tied to user behavior. Many users never scroll all
the way to the bottom of a webpage; they often find the information they
need at the top and navigate away.
- Zero Wasted Bytes: Without lazy loading, a user who
bounces from a page after three seconds still downloads all the heavy
images and iframes located at the bottom of the page. With
loading="lazy", if a user never scrolls down, Safari never requests those files from the server. - Server and Client Savings: This benefits both the website owner and the visitor. Website servers save money by transferring less data, and users—especially those using Safari on iOS and iPadOS devices with limited cellular data plans—avoid burning through their bandwidth allowances on content they never actually see.
Best Practices for Safari Implementation
To ensure Safari calculates the page layout correctly before the
lazy-loaded elements are downloaded, developers must include explicit
width and height attributes on the
<img> and <iframe> tags. This
allows Safari to reserve the correct amount of empty space on the page,
preventing sudden layout shifts when the user scrolls down and the media
finally loads. Additionally, you should never apply
loading="lazy" to images or iframes that are immediately
visible at the top of the page, as this will unnecessarily delay Safari
from rendering the initial view.