客户端服务器端模板nodejs [英] client side server side templating nodejs

查看:236
本文介绍了客户端服务器端模板nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nodejs开发webapp。我本来只是服务器端的hbs模板,但后来我发现了客户端模板的主干。我发现它可以从服务器获取数据然后使用hbs模板显示它,而不是服务器端生成整个html页面并发送。但后来我也读到了某些地方人们认为在客户端进行许多ajax调用以获取数据和显示一个网页并不是一个好习惯,它会对服务器有如此多的请求,而且页面似乎很慢。所以我想知道是否有一般规则可以为一个页面提出多少请求?我应该使用经典的一个请求吗?或者应该响应是一些客户端javascript,然后从服务器获取数据并显示它们?

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 ?

谢谢

推荐答案

我发现最好的解决方案是渲染您的模板服务器端,然后让您的Backbone应用程序将自身附加到服务器呈现的元素。我使用Jade作为我的模板引擎,这允许我重用模板服务器端和客户端。你应该花一些时间阅读 链接 。如果您确定这是您要查找的内容,请安装应用 此处

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.

我发现上述解决方案最不自满。您还可以非常快速地阅读代码并了解项目背后的想法。它只是汇集了许多不同的技术,有助于在客户端和服务器代码可重用性方面发挥最佳作用。在服务器端渲染时,即使是敏锐的表现也是如此。您还可以获得渐进增强的额外好处,并解决您在SEO和单页应用中遇到的任何问题。

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.

这篇关于客户端服务器端模板nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆