Architecture of a single-page JavaScript web application?

user65663 picture user65663 · Jun 16, 2010 · Viewed 50.4k times · Source

How should a complex single-page JS web application be structured on the client-side? Specifically I'm curious about how to cleanly structure the application in terms of its model objects, UI components, any controllers, and objects handling server persistence.

MVC seemed like a fit at first. But with UI components nested at various depths (each with their own way of acting on/reacting to model data, and each generating events which they themselves may or may not handle directly), it doesn't seem like MVC can be cleanly applied. (But please correct me if that's not the case.)

--

(This question resulted in two suggestions of using ajax, which is obviously needed for anything other than the most trivial one-page app.)

Answer

Dean Burge picture Dean Burge · Jun 16, 2010

MVC architecture of PureMVC/JS is the most elegant IMO. I learned a lot from it. I also found Scalable JavaScript Application Architecture by Nicholas Zakas helpful in researching client side architecture options.

Two other tips

  1. I've found view, focus, and input management are areas that need special attention in single page web apps
  2. I also found it helpful to abstract away the JS library, leaving door open to change mind on what you use, or mix & match should the need arise.