Monday, 5 March 2012

Javascript and Me

Javascript is like the kid with ADHD who wrecks a birthday party if he doesn't get the gift in pass-the-parcel ... but he is OK as long as you don't anger him.



We decided to invest heavily in Javascript and do away with creepy-uncle-PHP all together in favor of a pure Javascript frontend. That is, all user-facing code is ran in Javascript, in the browser (we're not using NodeJS or a Server side engine). Why?
  1. We didn't have enough developers to re-implement everything we do in Javascript (form validation, forms, bloody forms) in PHP. It took too long.
  2. We make a ton of mistakes. Undoing those mistakes was harder than it needed to be.
  3. Rapid development and testing of features was massively more important than browser support
  4. PHP was just talking via HTTP to a RESTish API anyway, and behaved like a shifty middleman.
 So, we dropped all server-side UI processing. This left us with a Javascript application talking to an API written in Python. This presented some problems:
  1. We had to have all browsers supporting Javascript to do anything useful. Given the proliferation of sites requiring Javascript, and our emphasis on early adopters the benefits outweigh the risk of a user using an old version of a browser or browsing without Javascript.
  2. Search engines were going to struggle with indexing us
  3. We had to deal with client-side caching of outdated Javascript
There are some upsides too:
  1. Once we let go of server-side processing outside the API, development was much faster. This is important when users give feedback that you can factor into features.
  2. The deployable code boils down to a Javascript blob and some static HTML templates (mustache templates) and a nice, neat API.
  3. Cheap to serve. Theoretically, the site could be downloaded and ran locally. The major costs are all in providing the API.
 We would not have been able to create our user-facing code entirely in Javascript without Backbone and Underscore and of course jQuery.

The Future
In the future we want to allow search engines to index our Javascript application. This isn't as straight forward as it sounds (even with Google's Javascript indexing). You still need the backend infrastructure to respond to those requests.