Ways to increase performance when set big value to innerHTML

后端 未结 7 1837
无人及你
无人及你 2020-12-05 08:25

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?

相关标签:
7条回答
  • 2020-12-05 09:15

    I've heard that innerText is about two times faster than innerHTML in IE. Not sure if it's true, though, but it might be worth a try.

    if (window.ActiveXObject) { // we're using IE
        document.getElementById('myElement').innerText = 'Bla bla bla bla';
        // or create a textnode:
        var txt = document.createTextNode('Lorem ipsum');
        document.getElementById('myElement').appendChild(txt);
    } else {
        // other code here
    }
    

    Update: Note that if you want to modify the HTML of myElement, don't use innerText – the HTML will be visible in plain text, like if you were using < and >.

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