Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax performance on getting data from backend?

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i implemented country,state drop down using ajax, servlets,jsp,hibernate.but my lead say's that using ajax to get data on change event will lead to slow performance is it correct? if yes please suggest me any other technology to bring drop down list dynamically.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Slow performance" is a completely meaningless phrase.

As you yourself suggest, you need to consider other approaches before you can declare that one option out of two or more is "slow". So just saying that some option is "slow" without saying that some other option is "faster" is not useful, especially if you don't have predefined response time requirements. (Which I suspect you don't.)

Also it might turn out that you have a couple of options for which the response time is 0.2 seconds and 0.3 seconds. Most web designers wouldn't consider either to be "slow", but one is certainly faster than the other.

So your question for your lead is "All right, then, what is the faster approach I should use?" If there isn't a faster approach, but the task has to be done anyway, then you and your lead would have to be satisfied with the "slow" approach which is the fastest possible.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ask your lead what he suggests that will lead to better performance...

In the crushing silence, go ahead and implement it using Ajax.
 
sachin potu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ajax means, for every change event fired an request will be sent to the server and the response need to processed , and the output is shown.
if your list of country's, state is small you can write a servlet , which generates one js file, and include this js file in the page and get the data
or you can directly put all the Country's and states in one js file, as the Country's or state's very rarely changed
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sachin potu wrote:yes ajax means, for every change event fired an request will be sent to the server and the response need to processed , and the output is shown.
if your list of country's, state is small you can write a servlet , which generates one js file, and include this js file in the page and get the data
or you can directly put all the Country's and states in one js file, as the Country's or state's very rarely changed


You really want to have to download that huge file? That is a bigger hit in performance than going to the server for small chunks.

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mallikarjun dontamsetti wrote:hi, i implemented country,state drop down using ajax, servlets,jsp,hibernate.but my lead say's that using ajax to get data on change event will lead to slow performance is it correct? if yes please suggest me any other technology to bring drop down list dynamically.


Incorrect when the backend is written correctly. A poorly written backend that makes a query every single time is going to be slow.

Point your lead to Google and ask if Ajax is so slow, how can Google make their autocomplete so freaking fast.



Eric
 
sachin potu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:
sachin potu wrote:yes ajax means, for every change event fired an request will be sent to the server and the response need to processed , and the output is shown.
if your list of country's, state is small you can write a servlet , which generates one js file, and include this js file in the page and get the data
or you can directly put all the Country's and states in one js file, as the Country's or state's very rarely changed


You really want to have to download that huge file? That is a bigger hit in performance than going to the server for small chunks.

Eric


if you collect all the countries and state the js will not be more than 50 KB i guess, and downloading an 50kb in this advanced world is not a big issue, today the servers are really fast and bandwidth is also bigger, once the js is downloaded the browsers will maintain the js file in cache, so if you think like this , this is not an bad idea

and one thing we can keep in mind is the countries and states change very very rarely
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sachin potu wrote:if you collect all the countries and state the js will not be more than 50 KB i guess


I would say you are underestimating. Probably you haven't thought about it at all but just picked a number out of the air which made your argument sound plausible. But on the other hand we don't know whether the actual requirement was all countries and all states anyway, so the point is really irrelevant.
 
sachin potu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
sachin potu wrote:if you collect all the countries and state the js will not be more than 50 KB i guess


I would say you are underestimating. Probably you haven't thought about it at all but just picked a number out of the air which made your argument sound plausible. But on the other hand we don't know whether the actual requirement was all countries and all states anyway, so the point is really irrelevant.


if you go to Contries.js and download the file its not more than 70 kb
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think bytes are free, I am scared to see how long it takes your app to load. 50k on a slow connection takes a long time.

I do not want to download 50k on my phone's browser.

Not everyone is on a fiber connection!

So not only does the user have to download the 50k, the browser has to also parse all or that code which also adds time.

Why make a user suffer when you can write a simple a simple backend that returns whatever the user needs. It can be pre ondexed to automatically return the values gzipped so the call takes milliseconds. I do this stuff for a living. It is not hard.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric is spot on. Ajax is a far superior solution than loading a bunch of data that may or may not be used on each page load.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic