title: Is it better to get all the needed data from the database once or is it better to make more often requests?
body: <p>So, I have to develop a web component with a help of CQ5 (a CMS in Java based on OSGi, Sling, JCR Content Repository)</p>
  
  <p>This component should do the following:
  Collect answers to three questions from the user, and then, based on those answers of the user, the response from the database will be provided to the user (one could say it's a calculator)</p>
  
  <p>The first question has 5 variants of answers, the second has 5 variants, and the third has also 5 variants.</p>
  
  <p>But the problem is, if the user has selected, say, option 1 as an answer to the first question, the number of possible answers the second question will be decreased - there will be only 3 possible answers left. </p>
  
  <p>For example, a user has questions:
  Which country are you from?
  Which state are you from?
  Which city are you from?</p>
  
  <p>If the user answers Canada to the first question, he will then be able to choose only Canadian states as an answer to the second question.</p>
  
  <p>So, on event when the form is changed by the user, the data in it should be updated through ajax</p>
  
  <p>So, the question is: is it better to get all the data at once from the database (there is not so much of it as you see), or is it better to make a request to database on each "form-changing event"? Or maybe, it doesn't make any difference?</p>
  
  <p>To my point of view, the second variant is better from the point of view of amount of code needed to be written, but what's better from the performance point of view?</p>