Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending data from a servlet to a javascript page

 
Colby Smith
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently running into an issue with a project where the time to load the data is taking too long for users. The time it takes to grab the data from the database and send it over to the javascript is fast. The time it takes to process the data on the javascript end is not.

When sending data over, I concat values as such: ("value1|value2|value3||value1|value2|value3..."). Then in the script I split the array based on the deliminator, and I know that the first value is, lets say, the name of the state. Then I know the second value is the number of email opens in that state, etc. I was thinking of doing JSON, but since JSON is based on a key-value system, would that be more data? Since the data I would be sending would be something like: ("stateName{count: value2, stateLongName: value3}").

Is the way JSON parsed faster than concatinating values into a string, then using JavaScript's 'split()' function to split them up as arrays and looping through them?

Thanks for the help!
 
Christian Taylor
Greenhorn
Posts: 8
1
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't feel that splitting a string or parsing JSON should really take much time on modern hardware and browsers, unless it's a serious ton of data but even then it's more likely what you're doing with the data afterwards. Have you profiled your Javascript so you know for sure where it's spending all of its time?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use JSON, not some proprietary format.

Then if there's a performance problem, we can pursue that.
 
Anurag Verma
Ranch Hand
Posts: 168
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Bear Bibeault, use Json....it performs awesome with UI, infact JSON=Java Script Object Notation. JSON is made for javascript and you can use AngularJS to save yopurself from writing JSON parsing code.
***Not trying to promote AngularJS, its just an example, there may be other frameworks too which I am not aware of.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With modern browsers, JSON is baked right into JavaScript so, in essence, all frameworks, or even using no framework, works well with JSON.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic