If you login to Facebook, Twitter or Gmail and view source, you’ll notice something very peculiar. All your Tweets and mail are rendered as JSON. There are no angle brackets. My guess is, this data is all dynamically rendered to the DOM. If you inspect any element on the page, you’ll see tons of divs and other HTML elements. None of which was served in the original markup. The questions are:
- Why would these 3 huge sites take time out to do this?
- Wouldn’t it be faster to just use HTML?
- Is it to save on bandwidth since the JSON payload is smaller to serve than HTML?
- Is it because these sites are heavily based on AJAX? My guess would be the former, but I have no idea. I’m not sure if you have to work for Google Twitter, or Facebook to know why this is, but this tactic is shared between the 3 sites, so I figure they have a common goal in mind. That makes me think it’s more of a general thing.
There are several reasons for their design that are commonly applied:
API driven architecture and separation mentioned in point #2 above allow the company to provide multiple channels delivery without too much rework. Consider if we want to build Twitter App for Android:
As you can see, this model provides a way for Google/Twitter to deliver into multi-channels without having to rewrite their logic. The same applies to Mobile WebView vs. normal Desktop WebView. All we need to change is the UI Layer and not the Data or Controller layer.
This is why they are taking time to think about the design and architecture it as such. A tight coupling between the data and presentation would require them to rework a lot of code in order to be delivered in multiple channels. It’s not about JSON vs. HTML or just the web but more of an architecture decision that would allow them to deliver their content to multi-channels (iOS, Android, third party App, Mobile WebView, Desktop View, Desktop App, etc). What you see in their HTML source is the manifestation of their strategy in WebView channel.