Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi to all,

I am newbie to web apps, with desktop app experience. Learning as I go with fabulous help from Larry's PHP/SQL book and his JS book. So useful. This forum seems fantastic too.

I think I can improve performance by loading the browser with data, stored in JS arrays. Since I am clawing my way forward, any feedback early on will be invaluable.

My app is about text management--creating custom comments on a person. A user comes to my site to select a group of people in a team and create a custom comment about each of them, based on job performance. The user needs to simply copy the new custom comment to the clipboard and paste it into another website (Yes, it would be better to write the text to the other website and No, I don't have access to that site).

The customized comments are never stored in MySQL, they only need to be generated on demand. The names and the stock comments are stored in MySQL. Here's my app model. I have already developed proof-of-concept code (or tested widgets) for the functionality and know it will work, my question is about any unanticipated pitfalls, and performance.

App launches:

  • User selects team of people
  • Server side: use AJAX to retrieve list of team members, list of stock comments
  • Client side: use JS arrays to store list of people and list of comments

 

In browser:

  • JS element: display only a list of people
  • Event: User selects person. Result: causes stock comment is written to a new JS text element, and a custom Copy to clipboard button is created
  • Event: button click. Result: custom comment is put in clipboard, so user can switch to reporting site and paste it in.
  • Repeat. Select next person. Creation of stock comment and new button element.
  • Logout when finished.

As you can see, I am using arrays to store data client-side, thinking this will improve performance. Users spend most of their time with the members of one team, so load the browser with the data and don't make unneeded AJAX calls.

 

When a user switches to another team:

  • JS clears the arrays
  • JS removes the recent text and button elements
  • JS clears the list of people
  • AJAX call gets new list of people and stock comments from MySQL
  • JS in browser now has arrays loaded with data.
  • User actions drive events and the process above repeats, until the user logs out.

The data needed for team members and for stock comments is relatively small, so JS arrays shouldn't cause a noticeable hit to performance.

All of this makes sense to me, but I see nothing like this being done in code snippets in books or on forums...and this makes me nervous! Previous experience suggests a more experienced coder will be able to alert me to pitfalls and guide me toward better design solutions. Any advice will be greatly appreciated!

 

CanuckCoder

Share this post


Link to post
Share on other sites

By the way I saw this comment from HartleySan, and thought my JS design made sense:

 

JS is usually used for the following two reasons:
1) Respond to user input.
2) Dynamically change the appearance/content of a page without reloading the page.

 

See: http://www.larryullman.com/forums/index.php?/topic/2112-forms-in-javascript-or-php/&do=findComment&comment=14534

Share this post


Link to post
Share on other sites

CanuckCoder, welcome to the forums. It certainly seems like you've done your research before making a post.

Thank you.

 

With that said, if you don't mind me asking, what is the point of your site?

Are you simply allowing users to comment on other users?

After a user has made comments, while aren't those comments uploaded to the server and saved?

In other words, what's the point?

 

Sorry for the harsh-sounding questions.

Share this post


Link to post
Share on other sites

Hi HartleySan,

 

I am not comfortable giving away the exact purpose of the site, for competitive reasons. I hope you understand. And I didn't think I had to defend the point of my project. That was a surprising comment to read.

 

As it happens, the comments for a performance assessment of team members by a manager, not about users on websites. The only user described is the user of the app. It is very worthwhile to a large group of users, it's ethical and it's something innovative (for their industry).

 

In my experience in desktop applications, I also did a fair bit of text management and I found arrays work well for me. So, does the design seem good? Just having a bit of newbie anxiety I guess. In books and online sample code I have not seen a lot of data being kept client-side in JS arrays. Do you have any words of caution or advise?

 

Thank you,

CC

Share this post


Link to post
Share on other sites

And no, the comments are not saved. As given,

 

The user needs to simply copy the new custom comment to the clipboard and paste it into another website...The customized comments are never stored in MySQL, they only need to be generated on demand.

Share this post


Link to post
Share on other sites

Sorry if my comments surprised you, and sorry for prying into the purpose of your site. That wasn't my intention.

I was just trying to get a better idea of what was going on so that I could better comment on whether your current implementation was best or not.

 

Anyway, if all you're storing are comments, then yes, I think an array is perfectly acceptable.

However, if you're storing several bits of information about a user, then I think an object would be better. You could then easily create an array of objects for the purpose of storing info about multiple users in one central variable.

 

So, yeah, I hope that helps.

I unfortunately cannot say much beyond that without knowing more about your site/project.

Good luck.

Share this post


Link to post
Share on other sites

Wow, I really like the tip about a User object array. Multiple payoffs there, down the road.

 

In fact the comments themselves have different variations--I was just keeping it simple for the sake of brevity (if you want to call my post above 'brief!' LOL)

 

... so ... Comment object arrays make sense too. Thanks very much, HS!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...