使用JQuery或其他类似框架从自定义url /Web服务加载HTML内容非常容易。到目前为止,我已经多次使用这种方法,并发现性能令人满意。
但是所有的书,所有的专家都试图让我使用JSON而不是生成的HTML。它为什么比HTML更优越?
它会快很多吗?
它在服务器上的负载是否非常小?
另一方面,我有一些使用生成HTML的理由。
它是简单的标记,通常和JSON一样紧凑,甚至更紧凑。
它更不容易出错,因为你得到的都是标记,而不是代码。
在大多数情况下,编程会更快,因为你不必为客户端单独编写代码。
你站在哪一边,为什么?
JSON is very versatil and lightweight format. I have discovered its beauty when I have started to use it as a client side template parser data. Let me explain, while before I was using smarty and views on server side (generating high server load), now I use some custom jquery functions and all the data is rendered on client side, using clients browser as template parser. it saves server resourses and on another hand browsers improve their JS engines every day. So the speed of client parsing is not an important issue right now, even more, JSON objects are ususally very small so they don't consume a lot of client side resourses. I prefer to have a slow website for some users with slow browser rather than slow site for everyone because of very loaded server.
另一方面,从服务器发送纯数据,你可以从表示中抽象它,所以如果明天你想改变它或将你的数据集成到另一个服务中,你可以更容易地做到这一点。
这只是我的个人意见。