I need to improve the performance of my application. At the moment I'm rendering several jQuery objects one at the time.
Example:
$.each(objects, function(i,v))
{
// Rendering each object
object.data('hi', v.value).appendTo('body');
});
Instead I would like to do something like:
var array = new Array();
$.each(objects, function(i,v))
{
// Storing each object
array[i] = object.data('hi', v.value);
});
// Rendering all objects at once
array.appendTo('body');
Is it possible to achive what I'm asking for?
Using DocumentFragment
as suggested by @Bergi:
var fragment = document.createDocumentFragment();
$.each(objects, function(i,v))
{
// Storing each object
object.data('hi', v.value).appendTo( fragment );
});
// Rendering all objects at once
$('body').append( fragment );
A working example: http://jsfiddle.net/4kTKG/1/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.