HTTP Requests are not fast... Well I guess they're sorta fast, if you do one. But if you do 300... not fast. As a matter of good practice and good user experience I've found that getting large blocks of data at a time to be much better than going back to the server for every element on the page.
Duh! Right? Well, this didn't really dawn on me until about 6 months ago. I wanted the data on a reporting page to filter when certain things were clicked on. It's sooo much faster to filter down the data you've gotten using Array.filter() rather than getting small pieces here and there. It would have made sense then too, but I didn't know how to filter the data. Then, when I started to figure that out, I noticed that when I would filter the data, that it would change in every instance. And then I learned the magic of scopes.
Scopes are basically levels at which data is kept. Turns out, that putting "var" in front a variable declaration makes it a local variable. I thought that the opposite was true for a very long time and I had a very bad time. If you don't understand javascript scopes, it is a topic worth every second of your time invested. Same with Array filtering, my life has been forever changed, and my code... so much more stable.
I would offer an example article but they're easy to find and I'm sad to say that I've lost the link to the best one ever. I'll update this post down the road when I find it again.
No comments:
Post a Comment