I've been using various server side languages/frameworks for developing back-end web applications. Every server-side framework that I've been using has the capability for returning views/templates (whole or part of a HTML page) as well as returning JSON responses which will then be interpreted by some front end JS.

I have heard the argument that returning JSON responses as opposed to some HTML with PHP/Python/ code snippets doing tasks such as looping through collections and printing out data/HTML elements in the template creates a more complete divide between frontend and backend of the application.

What are the main advantages of using JSON responses from the backend (and interpreting those JSON responses via some frontend framework) and creating a more RESTful type of application? And what are the main advantages of just returning templates/HTML to the client?

  • 2
    The fundamental reason you would have this kind of separation is so that you can support different kinds of frontends (i.e. Apple, Android, and web browsers) with the same backend. – Robert Harvey Aug 17 '16 at 22:10
  • 1
    Facebook is one of the few web apps that do this to the extreme. Once you login, Facebook ONLY serves a static page. All other data is rendered in the browser using JSON data received from the server. – slebetman Aug 18 '16 at 5:53
  • Similar question on stack overflow stackoverflow.com/questions/1148266/…, although that was specific to AJAX – david25272 Sep 8 '16 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.