This is for a single page, mobile web-app….
For readability I’ve been concatenating my html, then injecting. I’m pretty certain there’s a more efficient way, and would like to get a js expert’s opinion!
heres an example of one of my concatenated html strings…
var html_str = '';
$.each(events_array, function(k, ev_type){
if( localStorage.getItem('show_type'+ev_type.type_num) !== 'false' ){
$.each(ev_type, function(k2, e){
if(typeof e != 'string'){
if(fav_mode && last_date_num != e.date){
html_str += '<li class="date">'+e.date_text+'</li>';
last_date_num = e.date;
}
html_str += '<li';
if(fav_mode | (FAVOURITES && $.inArray(parseInt(e.event_id), FAVOURITES) >= 0) ){
html_str += ' class="fav"';
}
html_str += '>';
html_str += '<div class="l_'+e.gig_club+'"></div>';
html_str += '<p rel="'+e.event_id+'"><span>'+e.venue+' : </span>'+e.nameofnight+'</p>';
html_str += '</li>';
}
});
}
});
return html_str
There is no “Fastest”. There is only “Fastest” for a browser.
There are 3 common techniques. HTML string manipulation, templating and DOM manipulation.
Because templating can use both HTML string manipulation and the DOM internally I would recommend it for readability / maintainability.
Here are a few benchmarks
Templating
More templating
Templating with data for mobile platforms
Loads of templates
Dust js benchmark