Technical KnockOut

The other day I was working on a little demonstration of using OWIN to serve local files, use dependency injection, and server Web API in a modern SPA (Single Page Application).

Almost as an afterthought, I decided to use KnockoutJS and jQuery from a minimal HTML page. This was overheard by colleagues, and a firestorm erupted...

"You should have used AngularJS instead; It would take less lines of code."

So I pulled down AngularJS and changed my demo to placate the angry threats wishes of the religious zealots thoughtful developers at my desk.

For the record, this is the code I wrote using KnockoutJS and jQuery:
and here is the AngularJS version:

Trying to provide equally readable formatting, the Knockout solution takes one less line of code even though you are loading two JavaScript libraries. The only fair way to count lines is to count semicolons. Both have three. That's a tie.

What about the size of the libraries being loaded. Well, Angular includes a jqLite, a stripped down version of jQuery. It takes 50.5 kb. KnockoutJS takes 20.9 kb and jQuery 28.9 kb for a total of 49.8 kb. You can't say either one has much of an advantage there

I'm not going to argue the merits of one library over another. I think they serve different purposes. For the purposes of my very simple demo, I have a hard time seeing where either has any real advantage.

So, the answer is... do whatever makes you (or the barbarians at your gate) the most happy.

If you want to look at it, here is a complete GitHub repository with my solution.


Popular posts from this blog

KnockoutJS, WebAPI, and TypeScript

Database Projects, SQL Unit Tests, and TeamCity