I have an application running behind a proxy, both on the same machine. Which approach is more suited regarding compression, while preserving reasonable performance.

  • turn on compression at the application level (which happens to be in nodejs)
  • leave it out to the proxy (which is nginx)

closed as unclear what you're asking by Robert Harvey, user22815, gnat, user40980, user53019 Jan 16 '15 at 14:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Questions having the phrase "what/which is better" in them generally don't make very good questions for this site, because we don't know what "better" means to you. We prefer that you describe the specific problem you're trying to solve. – Robert Harvey Jan 15 '15 at 19:42
  • Means ? Well the question says "performanc"e – redben Jan 15 '15 at 20:46
  • The question says "compression and performance;" to optimize one, you often have to sacrifice the other. – Robert Harvey Jan 15 '15 at 21:00
  • Ok how come people answered my unclear question, and gave a clear answer. And other faved the question. And yes, the question says compression AND performance. Life is not black or white, you can doze both. – redben Jan 26 '15 at 16:09
  • 1
    That poorly-specified questions are not welcome here either, regardless of their supposed "conceptual" character. Real questions have answers, not opinions. – Robert Harvey Jan 26 '15 at 16:27

While this is probably a better question for ServerFault, I believe there is a clear answer: do compression on nginx.

There are a couple of reasons for this:

  • Compression is moderately CPU-intensive, and Node is single-threaded. Therefore, compression in node will potentially reduce the total number of requests a single server is able to handle.
  • You will almost certainly use nginx to serve static assets such as JavaScript, CSS, images, and static HTML. Which you will want to compress. So why not compress everything that goes through nginx, including forwarded traffic?

As for both: that's just wasted CPU.

  • Thanks for the answer PS: the third option was for fun :) – redben Jan 26 '15 at 16:10
  • This answer is just sort of wrong. For one, you do not want to compress everything that goes through; images come to mind. Secondly, Node.js uses a reactor pattern and IO is async, like gzip. Nginx uses the same event loop and thread pooling pattern. It makes very little practical difference where it happens. – Maletor Oct 16 '16 at 20:53
  • @Maletor - compression requires CPU, regardless of where it happens. If your Node server is spending its CPU doing compression, it doesn't have that CPU for other purposes. In any non-trivial web application, you want to offload as much as you can from the machines that are actually doing work. A front-end server is the standard solution to this. – kdgregory Oct 20 '16 at 11:36
  • Absolutely. But that prerequisites you have Nginx on another server. If it's on the same server I would imagine the end result would be of negligible difference; NGINX is superior in managing concurrency and would probably be slightly faster. – Maletor Oct 20 '16 at 19:49
  • A lot more opinions also on this reddit thread, interestingly they lean more towards letting node handle it - reddit.com/r/webdev/comments/3l1n5h/… – chrismarx Sep 21 '17 at 15:51

Presuming your nginx server fronting node is proximate to said node server you get just about nothing out of using things like compression between the two. You've got plenty of bandwidth between the two, why waste CPU saving it? Moreover, if you are doing any rewrites in nginx it gets ugly as nginx has to unzip the contents, replace, and re-zip. If it lets ya do it at all.

Not the answer you're looking for? Browse other questions tagged or ask your own question.