client side server side templating nodejs

拈花ヽ惹草 提交于 2019-12-22 10:35:34

问题


I am working on a webapp using nodejs. I was originally going to just server side hbs template, but then I found out about backbone for client side templating. I found out it can fetch data from server then display it using hbs template, instead of server side generate entire html page and send. But then I also read somewhere people suggest that it is not good practice to have many ajax calls in client side to get data and display for one webpage, it would have so many request to server, and the page would appear to be slow. so I am wondering is there general rule how many requests can be made for one page? Should I use classic one request one respond? or should the respond be some client side javascript which then fetch data from server and display them ?

Thanks


回答1:


I have found the best solution is to render your templates server side and then have your Backbone app attach itself to the elements rendered by the server. I use Jade as my template engine, which allows me to reuse the templates server-side and client-side. You should spend sometime reading this link. If you decide this is what you are looking for, then install the app here.

I find the above solution the least opinionated. You can also read through the code extremely quickly and get an idea behind the project. It's just a bunch of different technologies brought together, that help leverage the best in terms of client and server code reusability. Even the perceptive performance is drastic when rendering on the server side. You also get the added benefit of progressive enhancement and solve any issues you would with SEO and single page apps.



来源:https://stackoverflow.com/questions/24984903/client-side-server-side-templating-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!