Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHernán Garzón
6,605 PointsHow does XHR object affects the performance? Is it a very large and heavy API? Thanks
How does XHR object affects the performance? Is it a very large and heavy API? Thanks
3 Answers
Iago Wandalsen Prates
21,699 PointsAre you talking client-side or server side? On your client side, its going to cost your user processing the data it receives. Ajax functions are asynchronous, so the program make the call, keep doing your stuff, and when it gets an answer, it deals with the data it received. On server side it gets a little more complicated, it depends wether or not your server is asynchronous, but that should only matter if your server get a BIG traffic.
Ajax is not an API, its just a part of Javascript.
Chris Shaw
26,676 PointsHi Hernán,
An XHR
request in general won't affect your sites performance however it really depends on what you need to do with it as if you're making lots of requests to a single source that has a decent amount of data that can use up more memory of the users browser potentially slowing down the site in the process or even locking up the browser.
If you can provide an example of what you need to use it for it will help to determine ways to optimize the request and possibly even use real time caching.
Hernán Garzón
6,605 PointsI don't really have an example, it's a question that somebody did to me the other day and i didn't find any answer.
Real time caching is something you can do with javascript? Thanks.
Chris Shaw
26,676 PointsIndeed, the two most common options you have for caching are.
- Direct caching via the ajax request, all modern browsers support this and from memory IE8 has partial support
- Store data within your own custom arrays/objects and only request new data when requested otherwise use the cached data
Hernán Garzón
6,605 PointsThanks both of you :O)
Hernán Garzón
6,605 PointsHernán Garzón
6,605 PointsThank you very much for your answer!