I have been thinking lately about what should be executed client-side
vs. server-side and was curious what others thoughts are.
Let’s take the following example. A user has selected X pieces of
furniture. On a single page, they are
shown a list of the furniture items with specific info about each
piece (name, dimensions, manufacturer, list of parts etc). Much of
this info wouldn’t be shown by default but is expandable. The user
can delete furniture items or add new ones. When they add a new one it
is immediately added to the page without reloading.
Server-side heavy solution
You could implement this mostly server-side with some javascript to
expand info, add and delete items, etc. When the user added an item,
you could use AJAX to build the new block server-side and just add it
to the page when returned.
Client-side heavy solution
Server-side you could generate a simple javascript variable with the
page’s data (perhaps in JSON) and then generate all the page’s content
with javascript client-side (you would of course still do all the
layout server-side). This is actually much easier than it might
seem. Prototype has some nice DOM editing that is very clean.
My Thoughts
Lately, I am leaning toward the Client-side heavy solution for the
following reasons (feel free to argue with me):
- I make up that the server can handle more users because less work is
done there. (can someone verify or refute this?) - Cleaner delineation for presentation layer because all the main
content is present with javascript. If I want to change the way
things look, I just go to one place. If it is done server-side, I go
one place for initial presentation (server-side) and another for on-
page dynamic presentation (which has to be javascript). - Possibly better user experience because there is no delay between
adding an item and it showing up on their screen (don’t have to wait
for AJAX call to return). However, there would be a delay when the
page first loads while javascript creates the content (I use a “page
loading . . .” message that disappears typically in less than 1
second). I could for certain sites, that a delay when someone adds a
new item might be preferable to when the page just loads.
What are your thoughts?