Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are iframes so slow?

I have little bit longer question for you - but hope answer will be very simple :)

Let's say I have very simple page with link and iframe (just for simple example).

<body>     <a href="test.html" target="mframe">open link></a>     <iframe name="mframe" [params] /> </body> 

So when you click on the link it will load test.html in the frame.

Now I will change the iframe with div and ajax call.

<body>     <a href="doAjaxCall('test.html')">open link</a>     <div id="main-content"></div> </body> 

The doAjaxCall will simply use GET ajax requset to get whole response, parse it (using JavaScript) and grab content in <body> tag and put it into main-content.innerHTML.

test.html contains a lot of html, also css styles (but the same as are on parent page - so I don't need them when I'm using ajax solution).

Question:

Why is this ajax solution SO faster? I'm still downloading the same amount of data (downloading whole test.html).

Why is the iframe solution so slow? Is it because of browser have to parse all possible styles again? Or is there any other overhead of iframes?

like image 916
palig Avatar asked Jul 07 '09 12:07

palig


People also ask

Why you shouldn't use iframes?

Iframes Bring Security Risks. If you create an iframe, your site becomes vulnerable to cross-site attacks. You may get a submittable malicious web form, phishing your users' personal data. A malicious user can run a plug-in.

Are iframes being phased out?

IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.

Are iframes still used in 2021?

<iframe> is not an obsolete or deprecated tag. It's still widelly used in the web, mostly for media purposes.


2 Answers

You are pretty much on the right track. iframes are going to be slower because there is an additional overhead for the browser (rendering it, maintaining it's instance and references to it).

The ajax call is going to be a bit faster because you get the data in and you then inject it, or do whatever you want with it. The iframe will need to build an entirely new "page" in the browsers memory, and then place it in the page.

like image 110
Dave Morgan Avatar answered Sep 25 '22 12:09

Dave Morgan


Steve Souders has a post Using Iframes Sparingly on his High Performance Web Sites blog that may provide some more insight.

like image 31
Simon Lieschke Avatar answered Sep 24 '22 12:09

Simon Lieschke