[TriZPUG] web application best practices

Jim Allman jim at ibang.com
Fri Nov 4 18:18:08 CET 2011


Nathan,

FWIW, I've built websites using a lot of different tools. Just a few comments woven into your list..


> 2. avoid generating client specific code on the server as much as possible.

Agreed, though there are probably some systems that do a nice job of it. My main beef with lots of server-generated Javascript is that it tends to be awful to read and debug. I suppose the same is true of properly packed & minimized JS on a production site, but at least you have the option of developing and debugging with full source.

One simpe solution is to generate a few key variables on the server and bake them into the page for client-side use. If so, do this in the HEAD element (or otherwise manage JS load order), and certainly keep this code separate from the rest of your Javascript.

Oh, and if you're not already using it, please investigate Firebug (and similar tools) for client-side debugging and exploration.


> 3. separate out complex page elements into their own pages, then pull
> them in to a main page with an ajax load.

Alternately, define these elements with separate templates or components on the server side, and embed them directly into the larger page as it's being generated. Each can be best, depends on the situation. But sure, a modular approach means you're *ready* to refresh the page via AJAX, so you have both options.


> 4. Do not put ANY logic in your request handlers.  Just use them to
> collect and validate any URL arguments or post values, manage
> security, then call a separate function and generate a response from
> the result of that.

That sounds like a lot of logic, actually. :)  

But if you mean isolate the specific response, sure, there are lots of ways of accomplish this.


> 5. Avoid hand coding presentation functions for every class
> separately.  Create middleware layers, and implement functions on
> divergent classes that let the middleware generate the proper results.

My only caution here is that some of these measures can lead to a system that's nicely isolated, super-flexible, and a real pain to build and maintain. The more layers and levels of abstraction you add, the greater the learning curve for new developers. 

One nice thing about using an existing web framework is that a developer who knows its conventions can usually hit the ground running. And of course, a good framework will already encourage (or enforce) most of your best practices in some way.

  =jimA=



More information about the TriZPUG mailing list