Skip to content

Commit 9035ae8

Browse files
committed
Also updating append
Cloning the template content before growing it, expectedly, improves performance after adding and removing 10K rows. Without cloning, the large template persists in memory. It affects the page's responsiveness.
1 parent 82e10c0 commit 9035ae8

File tree

2 files changed

+2
-2
lines changed
  • frameworks

2 files changed

+2
-2
lines changed

frameworks/keyed/vanillajs-3/src/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let data = [], index = 1, i, lbl, selected;
99
function create(n = 1000) { if (tbody.children.length) clear(); append(n); }
1010
function append(n = 1000) {
1111
const nt = nTemplates(n); let j = 0, r1, r2, r3;
12-
const itemTemplate = document.getElementById('itemTemplate').content;
12+
const itemTemplate = document.getElementById('itemTemplate').content.cloneNode(true);
1313
while (nt >= itemTemplate.children.length * 2) itemTemplate.appendChild(itemTemplate.cloneNode(true));
1414
while (nt > itemTemplate.children.length) itemTemplate.appendChild(itemTemplate.firstElementChild.cloneNode(true));
1515

frameworks/non-keyed/vanillajs-3/src/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function set(n) {
2929
}
3030
function append(n = 1000) {
3131
const nt = nTemplates(n); let j = 0, r1, r2, r3;
32-
const itemTemplate = document.getElementById('itemTemplate').content;
32+
const itemTemplate = document.getElementById('itemTemplate').content.cloneNode(true);
3333
while (nt >= itemTemplate.children.length * 2) itemTemplate.appendChild(itemTemplate.cloneNode(true));
3434
while (nt > itemTemplate.children.length) itemTemplate.appendChild(itemTemplate.firstElementChild.cloneNode(true));
3535

0 commit comments

Comments
 (0)