I'm doing a small learning project, it takes a coin list from an API and then builds a page full of bootstrap card for the length of the array received from the API. While developing i only used 100 first coins to avoid long wait times, but now that I'm done when i try the entire 3900+ coins its takes an impractically long time.
I'm pretty sure the way i added the string is the source of the problem, I'll add my code and I'm sure it will all make more sense.
I tried building the entire string then append it - no good still slow. I tried changing it's innerHTML every time and then append it (append is inside the for loop), but it just overwrites all the older coins and appends only the last one.
What i want it to do is actually append each box separately and do it in a reasonable amount of time, right now it takes over 30 minutes to complete which is obviously not good.
The current version of code i added is the one that takes a long time but eventually does it right (although its only 50 iterations in the for loop so it doesn't get stuck if you try it right now, it needs to be over 3900 iterations)
function homeStart(coins: any[]): void {
var divcreate = document.createElement("div");
for (var i = 0; i < 50; i++) {
// console.log(coins[i]);
// ******This is where the string addup starts
divcreate.innerHTML += `
<div class="card text-dark bg-dark m-auto makeinline"
id="${coins[i].id}${i}" style="max-width: 18rem;">
<div class="card-header">
<div class="flexalign">
<span class="coinsymbol"
id="${coins[i].symbol.toUpperCase() +
"a1"}">${coins[i].symbol.toUpperCase()}
</span>
<label class="switch">
<input type="checkbox"
id="${coins[i].id}${coins[i].symbol}"
onchange="selectedCoinUpdate(this,'${coins[i].symbol}')">
<span class="slider round"></span>
</label>
</div>
</div>
<div class="card-body">
<div class="">
<h5 class="card-title coinname">${coins[i].name}</h5>
<button type="button" class="btn btn-secondary" data-
toggle="collapse" href="#collapseIdentity${i}" role="button"
aria-expanded="false" aria-
controls="collapseIdentity${i}"
onclick="moreInfo('${coins[i].id}')">More info</button>
</div>
<div class="collapse" id="collapseIdentity${i}">
<div class="card-body" id="${coins[i].id}">
</div>
</div>
</div>
</div>`;
}
// ******This is where the string addup ends
$("#pagecont").append(divcreate);
}