Document Fragments
Document Fragments kick ass for performance. Just ask John Resig. The following is code I used to convert a table's table-layout property from auto to fixed:
var tbody = this.scrollable.cache.tbody,
table = this.scrollable.cache.table,
tr = tbody.children(":first"),
children = tr.children(),
fragment = document.createDocumentFragment();
// go through the tds and create col elements in the fragment
for(var i =0; i< children.length-1; i++){
fragment.appendChild(
$("<code>").width(children.eq(i).outerWidth())[0]
);
}
//add the fragment to the top of the table
table.prepend(fragment)
//convert fixed
table.css("tableLayout","fixed")
I was hoping that something like $(document.createDocumentFragment()).append() would work, but no such luck. I'll probably submit a patch.
Using document fragments made the conversion to a fixed layout pretty much instantaneous. Hopefully you'll find this trick useful.
Related Content
About Jupiter
Jupiter is dedicated to making JavaScript an easy and enjoyable place to develop kick ass apps. We open-source everything and provide expert web application development, support, and training.
Recent Posts
- Significant Whitespace
- 3.2 $.Controller - Templated Event Binding
- Deferreds and 3.1
- jQuery Resize Event
- FuncUnit Humor
- Having your Cake and Eating it without Getting Fat
- Why You Should Never Use jQuery Live
- Knock JavaScriptMVC's Back Out
- Advanced jQuery Training at SF jQuery Conf 2011
- JavaScriptMVC and List Performance
JavaScript development, design, and consulting.