There are thousands of objects and chrome crashes every time I load everything at once.
btn.addEventListener('click', function(){
event.preventDefault();
async function getData(){
const response=await fetch(url)
const data= await response.json();
info(data)
}
getData();
function info(x){
x.messages.forEach(element => {
console.log(element.creator.name+": "+element.text)
// console.log(x.element.text)
con.innerHTML += "<p>"+element.creator.name+": "+element.text+"</p>";
});
}
This is the code im using rn
2
Answers
First innerhtml is slow because of parsing every time. Create a function to create Dom element and append it to the desired container. Adding paging or a flow to insert data in chunks can help too.
I created a Sandbox to try to simulate what the ask explained:
https://codesandbox.io/s/html-css-js-4jc8qh?file=/script.js
The code