Client vs. Server Side Web Programming

Status
Not open for further replies.

THBMan

Ars Legatus Legionis
18,256
Subscriptor
I'm currently entangled in the middle of a debate with a friend of mine over which direction the web interface of our project should go. One of the limitations of the server is that it's extremely low bandwidth (768/128 DSL), so we'd like to keep downloads to a minimum.

The project requires that a user-variable number of fields get filled in and submitted to be stored in a database. The number of fields is not known beforehand, neither is there any sort of reasonable boundary that can be placed for an upper limit.

I'm advocating client-side, where the fields are added and subtracted (as the case may be) dynamically by using Javascript and the DOM methods of manipulating pages. While this would add a bit of transfer to the initial download, it would prevent the user from having to query the server every time there is a change in the overall document. Plus, it has the added bonus of not requiring the whole page reload.

My friend is taking the side of the server. He wants to stick the variable section in an IFRAME and have that reload with the newly-formed fields inside. He says that the download of the new form will be less transferred data that the size of the javascript. His other main argument is that it will be compatable with all browsers, since there will be no javascript requirement and it's all HTML.

I'm uncertain as to what to do.

[Edit:]

Oh yeah, I should also bring up the possibility of using a src file for the javascript in the hopes of it being cached... and also the note that IFRAMEs don't work in older browsers.

<div align="right">The Happy Blues Man   </div>
 
So you basically want to have a form with a variable number of fields that the user can dynamically add to or subtract from before finally submitting the whole shebang.

I've done this in ASP and in PHP (server side, obviously) and think it could work just fine client side in JavaScript. You've got the pros/cons down pretty well so far too: the former works for everybody but is somewhat more server intensive, while the latter works without talking back to the server constantly, but relies on the client to function correctly and as expected, and is thus a brittle solution.

I suggest you do both, since it isn't difficult to do either. Detect whether the client supports JavaScript (even if it's just the one particular flavor) and if it does, send the JavaScript version, but if not, do it on the server-side. In the case with modern browsers, you get the benifit of not having to chit-chat back and forth just to figure out how many fields to show, and in the case of javascript poor browsers, it'll work anyway.
 
I vote for doing as much on the client-side as possible. If this is a 'for fun' project, why not just require the use of javascript in client browsers? A well-developed javascript include could save you a heap of bandwidth, and if your server's thin, you almost have to make the clients pick up some of the work... at least until you can get a pipe that can handle it.
 

sc_c77

Ars Tribunus Militum
1,660
I'd have to say it all depends on the level of security and the integrity of the data and your db server. If it's strictly client-side then you can get into the problem of people submitting eroneous info by bypassing the javascript.

What you could do is both in a sense. Do an initial check on the client and then when the form is submitted, recheck on the server before submitting the info into the db. The receipt you send back is plain text so you don't have to worry too much about bandwidth and you check the data integrity.

Of course if this is strictly for fun, go client all the way and save your server the extra work of checking the numbers before going to the db.

Hope this helps and if I'm way off, well...
 

Prototyped

Ars Legatus Legionis
11,126
Things like adding fields is fine when done client-side. However, I agree with the general consensus that doing it on the server side as well for a fallback is probably a good idea.

Client-side-only input validation is generally a no-no, however; you really, really want (mandatory) server-side validation as well, since it's always possible to spoof an HTTP request which says that JavaScript is enabled. The client-side validation will catch out bad input when the client is 'honest', saving a trip, and the server-side validation will catch bad input from 'dishonest' or script-disabled clients.
 
Status
Not open for further replies.