If you are reading this blog then chances are you are a software developer or at least interested in software. Software developers constantly have new frameworks, platforms, technologies, and such taunting us with new ways of developing software. Sometimes even suggesting the way you are currently developing is old and maybe even going so far as to claim the way we are doing it is "wrong". The message is that we should switch to this new shiny thing by claiming how much better it is at some specific thing and again maybe claiming it will solve all your problems.

Now you may be thinking I don't like AngularJS and that is not true. I actually think Angular has some nice features and is useful in some ways but I do not think it's "the" answer as some would have you believe. I found Angular's method of binding to be freaking sweet. I also like the idea of loading my JS and CSS once and not having to reload it again for the duration of the session. So far everything sounds great so what is the problem?

The Problems

Most applications I deal with need authentication / authorization so I always start with security in mind. My first task was to figure out how to handle authentication with my Web API. I thought that it would be no problem because I would simply used forms authentication and use the cookie to determine if I was authenticated. Such a great idea but it's just not possible. The ASP.NET authentication cookie is a HTTP only cookie which means you cannot access the cookie from JavaScript.

The second problem I had was how to handle the "remember my credentials" pop up that you get in the browser when you log into a website. Each browser has it's own requirements as to how this works and I would need to support each one. Interestingly the hardest to support is actually Chrome. Chrome requires you to do a post with a page reload. This means your login is required break the whole concept of your SPA design.

The third problem I faced was handling the form fill for the save credentials when loading the login page. The problem is a race condition. Who wins... AngularJS or the browser? This problem exists in all browsers. The browser does not wait for your JavaScript framework to initialize before filling in the username and password input values. This means when Angular get done initializing it does not know that the inputs have values. Now some people have thought of some hacks around it by delaying and then triggering the input but it is just hacks and they get messy quick. Also the hacks are not deterministic and may not always work.

The last problem I'll mention is the search engine problem. Search engines like the Google and Bing bots will load my sitemap then eagerly load each page. The problem is when they request the page they are only loading the templates. They do not run my Angular app and allow it to load the data. This means the search engine cannot get to my content to index it. However the search providers have provided a mechanism to find a pre-rendered or rendered on the fly version of the content but isn't that why we wanted to use Angular in the first place.

The Solution

I feel that Angular has its place but it's pretty obvious that it's not "the" answer. I converted my blog (this blog) back to simply use ASP.NET MVC and pre-render the content on the server. This makes it really easy for me to provide content the search providers and allow them to crawl my content. I will continue to use Angular for Become Epic and other applications that need more advanced user interaction and do not need access by search providers. There's still much room for improvement and I enjoy learning new technologies.

I'd suggest not getting so caught up in the hype that you forget that with all new technology comes new problems. There is no silver bullet... there is no magically pill... Also don't get so caught of the the "one" method that you fail to see all the other really awesome stuff going on around you. As a matter of fact I bet if you looked around there's probably a better way to solve your problem... then again maybe AngularJS is the perfect fit for your problem.

In the end try to make sure to keep an open mind and do some research yourself. Learn the pros and cons of technology before you dive head first... pssh, what am I saying sometimes you just have some fun and run with it. Live and learn but be sure to learn..

Rock on and Become Epic!