Iframe 加载技术和性能问题

前提话:
搞性能的人都知道高性能网站建设指南的作者steve讲了很多怎么处理代码,使你的网站速度很快。也包括讲了Iframe 的blocking问题,今天在网上看了Aaron的关于讲Iframe的性能提出了新的思路。好的东东要分享,决定做个翻译(虽然英文很差但好东东就要说出来)。在性能方面的东东国内确实讲得很少。
Iframe setTimeout() does not work in IE9
Chad Barnsdale of Unfinishedman.com mentioned to me on May 25 that the Iframe setTimeout() technique does not work in IE9. And he was right. The file that gets loaded into the iframe simply does not load. Nothing happens. I will dive into this sometime soon. It's probably something small with the JavaScript code.
在IE9中使用Iframe setTimeout()的方式不能工作。注释一下吧。在steve中讲了iFrame不阻塞时讲到可以使用Iframe setTimeout()可以解除阻塞,为了能了解setTimeout实现方式。我这里贴两段代码:
1.最为普通的iframe代码,blocking page
<iframe id=iframe1 src="iframe-empty.php?t=" width=95% height=150 border=2></iframe>
2.steve的setTimeout实现iframe代码
<iframe id=iframe1 src="" width=95% height=150 border=2></iframe>
<script type="text/javascript">
function setIframeSrc() {
    iframe1 = document.getElementById('iframe1');
if ( iframe1 ) {
  if ( -1 == navigator.userAgent.indexOf("MSIE") ) {
         t_iframe = Number(new Date());
   iframe1.src = "iframe-empty.php?t=";
  }
  else {
         t_iframe = Number(new Date());
   iframe1.location = "iframe-empty.php?t=";
  }
}
else {
  alert("ERROR: There was a race condition - the iframe doesn't exist.");
}
}
setTimeout(setIframeSrc, 5);
</script>
Demo:
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值