Tiny Frontend Logo
Posts 0121

On This Page

Lazy Load Offscreen Iframes

As more websites embed YouTube videos into their pages to provide richer content, and it indeed helps users access information more effectively.

However, without proper optimization, it can burden the original page's loading efficiency.

Deferred Loading of iframe Content

By default, browsers automatically load all content when a user opens a page, including any embedded iframes.

However, if we change the page loading rules to:

  • By default, do not load any content for iframes located at the bottom of the page (in the non-visible area).
  • Start loading the embedded pages only when the user scrolls near them.

We can significantly reduce the original page's loading time and the amount of data that needs to be downloaded.

Browser's Built-in Solution

The browser offers a built-in loading attribute for the iframe tag, which changes the loading logic of the embedded page by setting different values.

<iframe loading="lazy" src="..."></iframe>

It supports two values:

  1. lazy: Indicates the iframe is a good candidate for lazy loading.
  2. eager: Instructs the browser to load the iframe immediately.
Subscribe to read the full content

* Free subscribe to enjoy full content access.
* You can cancel anytime with 1-click.

Read Next

0120

Resumable File Upload

The cloud storage has become an indispensable file backup and sharing solution in our daily work. But have you ever considered:

Resumable File Upload
0119

Sending Notifications

The Notification API allows web developers to create and display desktop notifications to users.

Sending Notifications
0118

Higher-Order Functions (HOF) in JavaScript

In JavaScript, functions are treated as first-class citizens. We can use functions as values, assign them to variables, pass them as arguments to other functions, or even return them from other functions.

Higher-Order Functions (HOF) in JavaScript
0117

JavaScript Closures

This question frequently arises during interviews. If you're unsure, here is everything you should know!

JavaScript Closures
0116

Ordering Flexible Elements

In many cases, we rely on the flex-direction property to manage the display order of flexible items.

Ordering Flexible Elements
0115

JavaScript: Page Location

Whether you're a seasoned developer or just starting your journey, understanding how to manipulate the web page's location through JavaScript can be a very useful tool in your arsenal.

JavaScript: Page Location