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 trial

General Discussion

Minimizing AJAX Requests for Faster Web Application

Hi, I've been making a web application locally but when I use it on my production site it is slower than I would like, due to AJAX requests.

So I'm thinking of reducing the AJAX requests to speed it up, but I'm not sure if that is a good idea.

Currently, each time the user adds an item to a list, I add that new item to the database with AJAX, retrieve the list from the database and then use that response to redisplay the list.

I'm thinking it would be much faster if I instead added the new item to an array that I redisplayed, and then send the new item to the database, so that the list could be redisplayed without waiting for an AJAX response.

My hesitancy in reducing AJAX requests is due to the following:

The list will no longer be a true reflection of what is in the database. So if something went wrong, the user could add items to the list then upon page refresh discover that they hadn't been added.

I think I'd need to change a lot of my code. This is fine as long as I'm confident I'm making the right decision.

Minimizing AJAX requests to improve speed isn't something I've seen taught much, so I'm not sure if it's the best choice to make. Perhaps there are drawbacks I'm not aware of? Like maybe the array would easily get too large, making the app slow again? I don't know. Can anyone please advise me in the right direction?