Skip to content

Commit 10da63a

Browse files
authored
Merge pull request #103 from ihcsim/issue101
Fix Issue 101 - Better jQuery Pattern Append
2 parents a02378e + 34b0dbb commit 10da63a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

jquery-patterns/append.html

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<body>
88
<script>
99
/* Title: append
10-
* Description: use string concatenate and set innerHTML
10+
* Description: use string concatenate and set innerHTML. Note that it is recommended to use the
11+
* array.join technique to concatenate long strings.
1112
*/
1213

1314
// antipattern
@@ -34,9 +35,18 @@
3435
});
3536
$('#ballers').html(myhtml);
3637

38+
// concatenate very long strings
39+
var myHtmlBuffer = [];
40+
$.each(reallyLongArray, function(count, item) {
41+
myHtmlBuffer.push('<li>' + item + '</li>');
42+
});
43+
$('#ballers').html(myHtmlBuffer.join(''));
3744

3845
// References
3946
// http://paulirish.com/2009/perf/
47+
// http://www.sitepen.com/blog/2008/05/09/string-performance-an-analysis/
48+
// http://stackoverflow.com/questions/112158/javascript-string-concatenation
49+
// http://stackoverflow.com/questions/153381/javascript-string-concatenation-faster-than-this-example
4050
</script>
4151
</body>
42-
</html>
52+
</html>

0 commit comments

Comments
 (0)