I am pretty new to Web Application programming and so to OOP Javascript and the new Client-Server interactions. I am encountering some trouble wondering about how much AJAX I should use or how much data I have to save "locally" . Explainig it better: at the moment , to manage the data that I obtain from AJAX request , I push them in Data Structure like Array's and then I handle them helping myself rendering html through template. Now, was I wondering : is all this necessary? Do I really need to store all this data in Data Structures or I can make AJAX call for every action users do on my application? I apologize for the explanation but it's a difficult concept for me to explain in English. Thanks in advance
Going out to separate pages for simple small pieces data is much MUCH slower than referencing it locally. On the other hand, storing too much locally can start causing major issues as well. If all you want to do is store a few user specific variables, then do it locally. If you want to access and parse entire data dumps with hundreds of rows with tens of columns, do that server-side with AJAX. It's all about balance. Think of it this way: I store all my pens at my desk in a cup. I just use them to write and take notes, I have black, blue, red, and a pencil. This works well anything more would just be a hassle. But say I was a professional artist who needed hundreds or thousands of different pens and pencils of different types, storing all of this on my desk in cups would be a mess and inefficient. I would need to store them in boxes something where I could easily move around and find what I needed, even if I used them constantly this method would still be much more efficient than if I was to just put them all in cups on my desk. Hope that makes sense. Sorry, I needed an analogy and just happened to look over at my pens. :) | |||
|
The correct answer is: "It depends". See it all depends on your need what actually you want. If the requirement of data is huge then it is better to make just one ajax call and store the data in client side and can do further processing. This will slow cut down the extra time which will may be required in huge ajax requests. But in case you require small chunks of data, then making separate ajax requests for each data has no harm. It's enough to make it feel like that the data is always present, you just have to figure out how to show or process so it will feasible with user point of view. | |||
|