File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Ajax performance on getting data from backend? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax performance on getting data from backend?" Watch "Ajax performance on getting data from backend?" New topic
Author

Ajax performance on getting data from backend?

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 244

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
Bartender

Joined: Oct 14, 2005
Posts: 18881
    
    8

"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

Joined: Jan 10, 2002
Posts: 61606
    
  67

Ask your lead what he suggests that will lead to better performance...

In the crushing silence, go ahead and implement it using Ajax.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sachin potu
Greenhorn

Joined: Oct 22, 2011
Posts: 21
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Oct 22, 2011
Posts: 21
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
Bartender

Joined: Oct 14, 2005
Posts: 18881
    
    8

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

Joined: Oct 22, 2011
Posts: 21
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 61606
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax performance on getting data from backend?