Skip to content

Commit

Permalink
security problems & slow with huge json file
Browse files Browse the repository at this point in the history
forEach doesn't stops after the condition achieve so it complete looping through json file without need, and if the file is huge, this will make Sparling.js slow,
also it makes many requests to "window.history" and this makes security warns!
so use normal for looooooop
  • Loading branch information
HamzaElkotp committed Sep 22, 2022
1 parent 25f83dc commit 34c02a9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ function jsonRead(jsonpages, metatagArr = ["SPAname", "SPAurl", "SPAtitle"]){
ele.addEventListener('click',()=>{

// change title, url regardless of pages or json file objects order
data.forEach((item, dataI)=>{
for(let dataI = 0; dataI<data.length ; dataI++){
if(data[dataI][SPAname] == ele.getAttribute("SPAname")){
document.title = data[dataI][SPAtitle];
window.history.pushState("","",data[dataI][SPAurl]);
return false;
break
}
console.log(1)
return true;
})
}

elements.forEach((eles)=>{
eles.classList.remove("is-active", "is-primary");
Expand Down

0 comments on commit 34c02a9

Please sign in to comment.