JSON vs HTML Ajax response

后端 未结 2 546
孤街浪徒
孤街浪徒 2020-12-19 14:58

Which is faster, to return ajax in JSON and then process JSON response to render the html, or just have the Ajax response the raw html in a bunch of

  • 2条回答
    •  感动是毒
      2020-12-19 15:44

      As already mentioned, that depends. From a server side point of view it makes a lot of sense to let the client generate the HTML because just serializing JSON is faster and takes a lot of strain off the server because it doesn't have to deal with all the HTML generation. An additional benefit is, that you offer an API when returning JSON that can be used for more than just outputting HTML.

      If you want to take the work off the client it makes sense to generate the HTML on the server side.

      In the end the speed of it depends a lot on the technologies used. Both ways can perform extremely well but when done wrong either one will be slow.

    提交回复
    热议问题