Why Single Page Applications?
Another advantage of having all you client code and resources loaded up front and less dependency on the server is it would make your application easier to convert to a hybrid mobile app if the need arises in the future.
This doesn’t have to mean that your whole application sits in one big page. As long as you can separate functionality into multiple areas, then you could have one SPA per area or module. For example, a system that includes Recruiting, Operation, and Logistics, could have three separate SPAs.
A common scenario of web applications is the need to show data on the page that could be edited by the user and keep it in sync with the data on the client. This is where Knockout shines; it gives you responsive display and editor user interfaces with a clean underlying data model. Anytime you have sections of the UI that updates dynamically (e.g., changing depending on the user’s actions or when an external data source changes), Knockout can help keep these two pieces in sync easily.
In the MVVM architecture used by Knockout and Durandal you have:
- Model: Definition of your data objects, such as Sales Orders, Customers, etc.
- View: This is the HTML markup of your page. Using the HTML data-bind tag, Knockout binds the data in the associated model with the HTML code keeping both in sync automatically.
Even if you don’t see the need to go full-blown SPA, give Knockout a try. It will make your client code and your life better.
In my next blog post, we will apply the concepts that we’ve been discussing, plus take a deeper dive into Durandal, highlighting features such as routing, navigation, and composition.