Why are iframes so slow?

前端 未结 3 1476
我在风中等你
我在风中等你 2021-01-31 17:36

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).

相关标签:
3条回答
  • 2021-01-31 17:46

    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.

    0 讨论(0)
  • Steve Souders has a post Using Iframes Sparingly on his High Performance Web Sites blog that may provide some more insight.

    0 讨论(0)
  • 2021-01-31 18:11

    Although the browsers have improved since 2009, the fact that the browser needs to hit additional servers (assuming the iframes are for thrid-party content), or hit the local server again (assuming the iframes are for local content), this would still impact page performance. In general, additional HTTP requests will always have an impact on a page's performance. If it's possible to build the iframe after the page is loaded and than render the iframe's content, this would improve the initial page load. However, I think this would impact the pages performance while the iframe loads the additional content.

    0 讨论(0)
提交回复
热议问题