Home Web Front-end HTML Tutorial HTML web page production tutorial: Use iframe tags with caution_HTML/Xhtml_Web page production

HTML web page production tutorial: Use iframe tags with caution_HTML/Xhtml_Web page production

May 16, 2016 pm 04:42 PM
iframe

Using iframe can easily call pages of other websites, but it should be used with caution. It costs tens or even hundreds of times more performance than creating other DOM elements (including style and script). Time comparison of adding 100 different elements shows how performance-intensive iframes are:

Pages that use iframes usually don’t have so many iframes, so you don’t have to worry too much about the time it takes to create the DOM. What is more worthy of concern is the onload event and connection pool.

iframe blocks onload

It is very important that the onload event of window is executed as soon as possible. This will complete the browser's loading progress indicator, which the user will use to determine whether the page has finished loading. The delay of the onload event will make the user feel that the page is slow.

The window's onload event will not be triggered until all the iframes it contains and the resources in all iframes are completely loaded. In Safari and Chrome, using javascript to dynamically assign a value to the iframe's src can avoid this blocking behavior.

A connection pool

The browser only opens a very small number of connections to each web server. Older browsers, including IE 6/7 and Firefox 2, only have 2 connections per host. In new browsers, the number of connections increases. Safari 3 and Opera 9 have increased to 4, and Chrome 1, IE 8 and Firefox 3 have increased to 6.

One might expect a separate connection pool for each iframe, but this is not the case. In most browsers, the connection is shared between the main page and its iframe, which means it is possible for resources in the iframe to occupy the available connections and block the main page's resource loading. This is fine if the content in the iframe is equally important, or more important than the main page. However, under normal circumstances, the content in the iframe is not important to the page, and it is not advisable for the iframe to occupy the number of connections. One solution is to dynamically assign a value to the iframe's src after the higher-priority resource is downloaded.

5 of the top 10 websites in the United States use iframes. Most of them are used to load ads. This isn't a great fit, but it's understandable and is an easy way to insert ads into your content. In many cases, using iframes makes sense. But be aware of the performance impact this has on your page. Please use it with caution unless necessary.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I crop an IFrame in HTML? How do I crop an IFrame in HTML? Aug 29, 2023 pm 04:33 PM

How do I crop an IFrame in HTML?

What does data-id in iframe mean? What does data-id in iframe mean? Aug 28, 2023 pm 02:25 PM

What does data-id in iframe mean?

Why does iframe load slowly? Why does iframe load slowly? Aug 24, 2023 pm 05:51 PM

Why does iframe load slowly?

What technology can replace iframe What technology can replace iframe Aug 24, 2023 pm 01:53 PM

What technology can replace iframe

Microsoft: Outlook error downloads 'TokenFactoryIframe' file on every visit Microsoft: Outlook error downloads 'TokenFactoryIframe' file on every visit Apr 19, 2023 am 08:25 AM

Microsoft: Outlook error downloads 'TokenFactoryIframe' file on every visit

What are the loading events of iframe? What are the loading events of iframe? Aug 28, 2023 pm 01:55 PM

What are the loading events of iframe?

What's the danger in iframes What's the danger in iframes Sep 08, 2023 pm 03:14 PM

What's the danger in iframes

What does iframe mean in Python? What does iframe mean in Python? Aug 25, 2023 pm 03:24 PM

What does iframe mean in Python?

See all articles