dotjay / hashgrid

A little tool that inserts a layout grid in web pages, allows you to hold it in place, and toggle between displaying it in the foreground or background.
https://dotjay.github.io/hashgrid/
Other
446 stars 46 forks source link

Append optimization in loops #6

Closed ajaswa closed 13 years ago

ajaswa commented 13 years ago

I noticed that there was a slow down when testing a rather long page in IE7, while I'm not 100% sure that hashgrid was the culprit, I did find it odd that you would call jQuery's append() inside of a for loop. This amounts to calling appendChild as many times as you have grid lines, on the hashgrid website its about 180 times.

I've pulled the append() to outside of the for loop so it's only called once rather than (pageHeight / lineHeight) times ( which could get quite big ).

This may also fix the Firefox unresponsive script issue that has been reported. Though I have not tested this.

Thanks, Andrew

dotjay commented 13 years ago

Good catch, Andrew. I've been wanting to find time to make improvements such as this. Getting help is just one reason I love GitHub and open source code. :-) Thanks.

ajaswa commented 13 years ago

No problem. If I find some time I'll make a few more changes. I noticed a couple of other areas that could be improved but this one was the biggest.