【发布时间】:2014-01-24 13:01:01
【问题描述】:
所以我正在处理这个页面,它是一个在线目录。您在搜索栏中输入内容并加载结果。在结果中,您可以单击您想查看的图像,然后一个大图像和一些细节出现在 iframe 中。我的问题是,当有很多搜索结果时,iframe 的加载速度非常慢并且也关闭了,但是当只显示几个项目时,它运行得相当快。有谁知道为什么?
<script>
//this affect the content that is loaded in the iframe when image is clicked
$( document ).load( "pageinit", "#page1", function() {
$(".popupInfoLink").on("click", function(){
var url = $(this).data("popupurl");
$( "#popupInfo iframe" ).attr("src", url);
});
//this clears the frame when you navigate away
$("#popupInfo").on("popupafterclose", function(){
$( "#popupInfo iframe" ).attr("src", '');
});
});
下面是影响 iframe 的脚本和运行该脚本的缩略图。
<div>
<a class="popupInfoLink" href="#popupInfo" data-rel="popup" data-position-to="window" data-popupurl="product.asp?itemid=[catalogid]"><img src= "/[THUMBNAIL]" style="max-height:300px; min-height:150px;" alt="pot" border="0" />
</a>
</div>
<div data-role="popup" id="popupInfo" data-overlay-theme="a" data-theme="d" data-tolerance="15,15" class="ui-content">
<iframe src="about:blank" width="100%" height="200px" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');" allowtransparency="true"></iframe>
</div>
我的问题是,如果在两种情况下都只加载一个 iframe,为什么在搜索结果中显示更多项目时 iframe 加载速度会显着减慢,而不是仅加载几个项目?
【问题讨论】:
-
瓶颈在你的服务器端。 ASP 需要一些时间来返回结果。您可以通过在 iframe 中添加加载程序(微调器)来改善用户体验,当从服务器(通过您的搜索)检索内容时,它会替换微调器。
-
是的,我正在考虑这样做,添加一些小动画 gif。另一个答案可能是使用 ajax 而不是 iframe,你们怎么看? @jamesemanon
标签: javascript jquery html performance iframe