ajax html vs xml/json responses - performance or other reasons

前端 未结 8 1295
死守一世寂寞
死守一世寂寞 2020-12-05 09:58

I\'ve got a fairly ajax heavy site and some 3k html formatted pages are inserted into the DOM from ajax requests.

What I have been doing is taking the html responses

8条回答
  •  既然无缘
    2020-12-05 10:26

    I'm currently wrestling with this decision too and it didn't quite click until I saw how Darin boiled it down:

    "If the data is going to ever be used outside of your application HTML might be harder to parse and fit into other structure"

    I think a lot of it is where/how the data is going. If it's a one-off application that doesn't need to share/send data anywhere else, then spitting back pure HTML is fine, even if it does weigh more.

    Personally, if there is complex HTML to be wrapped around the data, I just spit back the HTML and drop it in. jQuery is sweet and all, but building HTML with Javascript is often a pain. But it's a balance game.

提交回复
热议问题