当将big值设置为innerHTML时,提高性能的方法 [英] Ways to increase performance when set big value to innerHTML

查看:89
本文介绍了当将big值设置为innerHTML时,提高性能的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力为节点的innerhtml设置一个巨大的(200K)响应。
目标是在互联网浏览器6中获得比2.7秒更好的时间。
任何想法?

I'm trying to set a huge (200K) response to innerhtml of a node. The goal is to get better time than 2.7 sec in internet explorer 6. Any ideas?,

谢谢

推荐答案

这不会让它发生得更快,但会阻止浏览器锁定用户;他们可以继续使用页面,而这种情况发生在后台:

This won't make it happen any faster but it will stop the browser from locking up on the user; they can continue to use the page while this happens in the background:

function asyncInnerHTML(HTML, callback) {
    var temp = document.createElement('div'),
        frag = document.createDocumentFragment();
    temp.innerHTML = HTML;
    (function(){
        if(temp.firstChild){
            frag.appendChild(temp.firstChild);
            setTimeout(arguments.callee, 0);
        } else {
            callback(frag);
        }
    })();
}

使用它:

var allTheHTML = '<div><a href="#">.............</div>';
asyncInnerHTML(allTheHTML, function(fragment){
    myTarget.appendChild(fragment); // myTarget should be an element node.
});

此技术将比普通 innerHTML ,但用户将能够继续使用您的网站,而不会出现延迟。

This technique will take longer than plain innerHTML but the user will be able to carry on using your site without noticing a delay.

这篇关于当将big值设置为innerHTML时,提高性能的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆