I have built several mini-SPA apps using both Knockout.js and Ember.js. There are a lot of good reasons for serving a mini-Single-Page-Application rather than converting your entire app, mainly that client-side code doesn't do everything better.
In my experience, both Angular and Ember.js are very useable without making your whole app client-side. Ember gives you some very useful tools for making "widgets".
For example, if I want my Ember application to render on a part of my server-side page, I can do this:
var App = Ember.Application.create({
// Set the rootElement property to the div that I want my ember app to render inside
rootElement: "#your-root-element",
Resolver: Ember.DefaultResolver.extend({
resolveTemplate: function(parsedName) {
// Override this method to make this app look for its templates in a subdirectory
}
}),
});
// Don't render the app on any page by default
App.deferReadiness();
// Instead, check to see if the #rootElement is present on the page before rendering.
$(document).ready(function() {
if ( $(App.get('rootElement')).length > 0 ) {
App.advanceReadiness();
}
});
I'm sure you can do similarly with Angular.js. I prefer Ember for the following reasons:
- A genuine class/mixin system. This is really helpful when you want to share code: it should be very familiar to anyone who is used to working on the server side.
- Very flexible templating.
- Clear separation of concerns, allowing many different views and such to be handled elegantly.