简体   繁体   English

iframe与Ajax(JSON)之间的性能差异

[英]Performance difference between iframes vs ajax (JSON)

Are there any performance differences when I would load up a formatted element through an iframe or via an ajax call retrieving json data and let javascript put it in a html design? 当我通过iframe或通过ajax调用来检索json数据并让javascript将其放入html设计中以加载格式化的元素时,是否存在性能差异? I tend to look at how major websites are doing it and i noticed that ebay uses a lot of iframes. 我倾向于看看主要的网站是如何做到的,我注意到ebay使用了很多iframe。 On the homepage there are like four iframes, one of them is obvious though since it's an advertisement. 在首页上,有四个iframe,尽管其中一个是广告,但很明显。

Also, within an iframe i can't access the parent's javascript files although it's on the same domain, so within the iframe i have to load the .js file again. 另外,在iframe中,尽管它位于同一域中,但我无法访问父级的javascript文件,因此,在iframe中,我必须再次加载.js文件。 I wonder whether this is a technical issue or safety precaution in terms of XSS which is still weird because it's on the same domain... An example is the jquery .js distribution file, I have to load this in both the parent and the iframe. 我想知道这是XSS方面的技术问题还是安全预防措施,因为它在同一个域上,所以仍然很奇怪。例如jquery .js分发文件,我必须将其加载到父级和iframe中。 Would browsers use the parent's cached version of this or download the whole .js file again? 浏览器会使用父级的缓存版本还是重新下载整个.js文件?

This is actually a number of questions. 这实际上是许多问题。

First I'll address overall speed: Short answer: it depends. 首先,我将介绍整体速度:简短的答案:这取决于。 There are a number of factors here. 这里有很多因素。 Ajax method - probably faster to load the data from the server, slower to display client-side. Ajax方法-从服务器加载数据的速度可能更快,而在客户端显示速度则更慢。 IFrame method - probably slower to load from server, faster to display client side. IFrame方法-从服务器加载的速度可能较慢,显示客户端的速度较快。

I would think the trend towards using iframes for ads is more to do with security concerns and overall design requirements. 我认为将iframe用于广告的趋势更多与安全性和总体设计要求有关。

Within the iframe, if it loaded from the same domain as the parent, you should be able to do parent.$ or parent.jQuery . 在iframe中,如果它是从与父目录相同的域中加载的,则您应该能够执行parent.$parent.jQuery See this question . 看到这个问题

Caching introduces a whole extra layer into this. 缓存为此引入了额外的一层。 Caching will probably happen, though it really depends on browser settings or proxy settings even. 缓存可能会发生,尽管它实际上甚至取决于浏览器设置或代理设置。

Well it completely depends on how and from where the data/html is coming from. 好吧,这完全取决于data / html的来源和来源。

If the html content is coming from then cdn network or from other domain and you just want to display the data of a link and you all the working functionality of that other content, then at somepoint iframe is good. 如果html内容来自cdn网络或其他域,而您只想显示链接的数据,并且该其他内容的所有工作功能都正常,那么iframe有时会很好。

While to load the data fast and with performance i think ajax functionality will be more preferable. 虽然可以快速且高性能地加载数据,但我认为ajax功能会更可取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM