PDA

View Full Version : More Speed by using document.write in empty iframes instead of innerHTML?



wm003
12 Oct 2007, 9:23 AM
Just a suggestion:

i recognized in my other (non ext-) projects, its incredibly faster to create new DOM Elements by storing them into an empty iframe by using document.write instead of using innerHTML.

In my tests i tried to dynamically change a huge list-element with 3500 elements completely.

By using innerHTML, it took about 10 seconds ... but by storing the string with document.write into an empty iframe it took just 100ms (!!) The iframe was exactly positioned as where the div container (when using innerHTML) would be positioned, so the layout was still the same.

Maybe thats an option to get especially the "grid-with-thousands-of-rows-without-using-paging-is-slow"-problem get solved or just much more faster? Jack, what do you think?

e.g.

assume HTML_String has about 3500 or more elements inside like
<li><span></span><code></code></li>slow


document.getElementById("myDiv").innerHTML = HTML_String;fast


writeFrame.document.open();
writeFrame.document.write(HTML_String);
writeFrame.document.close();

JeffHowden
12 Oct 2007, 10:30 AM
The only issue is that document.write isn't supported in XHTML doctypes.

hendricd
12 Oct 2007, 11:25 AM
I just tried the XHTML Doctype written to an Iframe for a new ux.ContentPanel im currently testing. It didn't have any trouble at all accepting the entire page I wrote to it:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
I'll try the from next...

Update: Nope, works fine both from and to (IE and Gecko).

JeffHowden
12 Oct 2007, 12:12 PM
Likely you aren't serving the XHTML docs with the correct mimetype then. Here's a few links of interest:

http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite
http://ejohn.org/blog/xhtml-documentwrite-and-adsense/
http://www.456bereastreet.com/archive/200501/the_perils_of_using_xhtml_properly/

Probably the reason you're getting away with it is that you're using it to write to the entire DOM as opposed to using it to insert markup into the DOM during page parsing/rendering.

hendricd
12 Oct 2007, 12:19 PM
Thanks I'll check those out, and do some more test...~o)

hendricd
12 Oct 2007, 1:13 PM
Those articles raise some questions (in my mind):

1: Anyone have Ext 1.1.x+ running on XHTML 1.0 or higher ? Strict, frameset or otherwise ?
2: is current (or future) Ext.domHelper comfortable in that environment when useDOM = false ?

:(

wm003
12 Oct 2007, 11:27 PM
Probably the reason you're getting away with it is that you're using it to write to the entire DOM as opposed to using it to insert markup into the DOM during page parsing/rendering.

Thats exactly the point, why its much more faster. And especially when using huge grids, speed matters. You just write the entire DOM of the grid element, not the whole page-markup. Maybe that breaks some Doctype rules, but if its working in most used browsers, why not using ist, when the performance will be dramatically increased (again, you should not use it anytime, but with huge grids the difference of performance is noticeable