Tags

Jan 22, 2012

Good Practices for Rich Web Applications


Use jQuery
jQuery is the best thing that has happened to Javascript. The library is elegant, powerful and has exactly the right level of abstraction for working with the DOM.
Learn it and use it. Good resources are: the jQuery API,

Learn Javascript
Javascript is the programming language of the web. Learn it! Javascript is different from most other programming languages. 
If you want to learn Javascript you should get the following books, The Little Schemer, The Seasoned Schemer, Javascript, the Good Parts, and possibly High Performance Javascript
 
Learn CSS 


Many programmers think that CSS is the language of designers and not programmers. This is not the case at all. If you are lucky enough to have a designer on your team (most people don't), CSS is the language with which you communicate. It is the interface between designers and programmers and as a programmer you should know it better than the designers.
It will also be up to you to keep the HTML clean, and a good way to do this is to use semantic HTML, combined with CSS. You have no idea what the designers can come up with.

Decide how "Rich" your application should be


How rich should your application be? The scale varies from no Javascript to only Javascript, but you will probably want to land somewhere in between. Here are a few suggestions.
  • No Javascript, everything is server generated.
  • Slightly enhanced pages, simple validations, but no Ajax.
  • Ajax enhanced pages, but every page still reloads frequently.
  • Single page per area, entire area is handled by Javascript.
  • Only Javascript, Ajax interaction with the server
  • Only Javascript, no interaction with the server

    Html
    HTML is code! Divide your pages into partials by responsibilities. It allows you to keep your pages DRY and readable. The Single Responsibility Principle applies to HTML too.
    Make sure you keep the Javascript with the code that it manipulates. If you, for example, have a calendar partial that uses jQuery DatePicker, you have to make sure that the partial includes all the necessary Javascript to configure the calendar. Don't keep Javascript code in the page away from the partial. Things that change together should be together.
    Use clone()
    Separating the HTML and the Javascript goes both ways. Don't generate HTML code in Javascript. It doesn't matter that it is super simple to do it using jQuery.html(). Keep them separate, use jQuery.clone() instead.

    The point of this is, again, to keep the HTML separate from the Javascript.
    Conclusion :
              We have to realize that we are responsible for the entire application, not just the business logic, but  the HTML and CSS too

No comments:

Post a Comment