简体   繁体   English

NodeJS,Express,Nginx和Jade……交易如何?

[英]NodeJS, Express, Nginx and Jade… whats the deal?

So I'm currently investigating what technologies/libraries etc to adopt for a new, rather large scale project... 因此,我目前正在研究为一个新的,相当大规模的项目采用什么技术/库等。

Given my teams knowledge of NodeJS, JavaScript, Express and Jade (now Pug) I/WE would ideally like to adopt these for the new project. 考虑到我的团队对NodeJS,JavaScript,Express和Jade(现在称为Pug)的了解,I / WE最好在新项目中采用它们。

However, the current sticking point is the way in which HTML is being served under Express using route middleware. 但是,当前的症结在于使用路由中间件在Express下提供HTML的方式。

We all know that Node/Express does a pretty bad job of serving up static files, which is where Nginx comes in. I can understand and even implement an Nginx config that handles the serving of img/js/css static files but what I'm trying to find out is this... 我们都知道Node / Express在提供静态文件方面做得很糟糕,这就是Nginx的所在。我可以理解甚至实现一个Nginx配置来处理img / js / css静态文件的提供,但是我所做的是我试图找出是...

Can the serving of HTML (generated by Jade/Pug), using Express routes be handed over to Nginx in order to boost performance? 是否可以将使用Express路由的HTML服务(由Jade / Pug生成)移交给Nginx以提高性能? Or is it the case that if you're using Express routing, you have to accept that serving of HTML files will be slow? 还是在使用Express路由的情况下,您不得不接受HTML文件的投放速度会很慢的情况?

Got to be honest, I'm not quite sure how all this fits together so am hoping someone can shed a little light on this ;-) 老实说,我不太确定所有这些如何组合在一起,因此希望有人可以对此有所了解;-)

Thanks in advance guys and gals 在此先感谢伙计们

Without questioning for more details, I can point out some things i keep in mind when developing on Express: 在不质疑更多细节的情况下,我可以指出在Express上进行开发时要记住的一些事项:

  • Express "default" rendering done through res.render may not be optimal for a number of reasons. 由于多种原因,通过res.render进行的快速“默认”渲染可能不是最佳的。 For example, lookup for the template file which is recalculated every request 例如,查找每个请求都重新计算的模板文件
  • Jade template engine doesn't support streaming Jade模板引擎不支持流

I would suggest, before looking at interventions outside application context (such as Varnish or plain Nginx conf), to try: 在查看应用程序上下文之外的干预措施(例如Varnish或纯Nginx conf)之前,我建议尝试:

  • using a template engine supporting streaming: Marko , Dust , Nunjucks 使用支持流式传输的模板引擎: MarkoDustNunjucks

  • if the app is a single-page, or generally an ajax based one, and you don't need any special SEO setup (although, there are fixes for that too), you may also pre-cache the static html then fill it up on the client (but this is really just a rant). 如果该应用程序是单页面,或者通常是基于ajax的页面,并且您不需要任何特殊的SEO设置(尽管也有针对此的修复程序),则您也可以预先缓存静态html,然后填充它在客户端上(但这实际上只是一个咆哮)。

A good overview comes from Strongloop's blog post 一个很好的概述来自Strongloop的博客文章

Reasonable recommendations: 合理的建议:

  • Serve static files with NGINX, you can configure it to fetch the files directly. 使用NGINX服务静态文件,您可以将其配置为直接获取文件。
  • Serve dynamic files with NGINX proxied to your express app, and set an adequate cache value. 使用代理到您的Express应用程序的NGINX服务动态文件,并设置适当的缓存值。

Can the serving of HTML (generated by Jade/Pug), using Express routes be handed over to Nginx in order to boost performance? 是否可以将使用Express路由的HTML服务(由Jade / Pug生成)移交给Nginx以提高性能?

Yes if you cache. 是的,如果您缓存。

Or is it the case that if you're using Express routing, you have to accept that serving of HTML files will be slow? 还是在使用Express路由的情况下,您不得不接受HTML文件的投放速度会很慢的情况?

Not if you cache. 如果您缓存则不行。

I hope that helps! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM