JavaScript Architecture – Should Web Applications Be Rendered by JavaScript with Backend Delivering JSON?

apiArchitecturejavascriptjson

As a programmer, and taking into account the overall "funness" of the process, I'm tempted to start a project in Sinatra where the back end's sole concern is the logic, and returning a Json API, and then writing a javascript application that would interact with that API for rendering the actual content to the user.

I'm fairly new to programming and I've never done anything remotely like this before. What would be the pitfalls, advantages and disadvantages of completely separating logic from presentation in such a way? Any examples of this being done in the wild?

One concern off the top of my head is how would search engines respond to a site whose content is almost entirely served as Json…

Best Answer

Most of the web apps I've written for my firm works this way -- a single page, javascript driven application making ajax calls to a back-end service.

So when I started my own website, my first implementation was done the same way. However, more than halfway through the development, I realized I made a big mistake.

My website offers content to my users, and this content needs to be available via search engines. I also need to monetize my website via ads. The problem is that both these requirements depend on the static content avaiable from the website.

Static content is required to index keywords for search and to display relevant ads. These keywords are fetched from the text found in the underlying HTML. If your content is fetched from a remote source and displayed via javascript, it's likely that your underlying HTML would be mostly blank.

Because they provide a rich client experience, dynamic pages are ideal for web-based applications. However, if you intend to deliver content, it's best to avoid dynamic pages.