'Better approach in cloning elements for Datatables custom renderer

I have a custom renderer for a column in DataTables. As you would know, DataTables expects the custom renderer to return a literal representation of what you would like to display on that column. Something like:

return '<div class="fancy">' + somevalue + '</div>';

I am already using this approach but I wonder how I could do it better. Like for example saving the template somewhere and returning it cloned. Consider this custom column rendering returns a big nested element. Is it still wise and ok to return it just like how it is now? Or is it better to use other approaches like HTML5 templating (with querySelector()) or jQuery .clone() method? Though either of these methods can't return a literal representation but only a node or a DocumentFragment which must be appended to the DOM before use. But are they still viable options here?

Things to consider here is maybe reducing the DOM footprint? Client-side and/or server-side performance? Better coding approaches?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source