Search code examples
expressnginxcompression

When combining nginx with expressJS, shall I use compression in express or nginx?


I have an app running on nodeJS/express and also using nginx. If I compress the served files on both systems, I suppose that slows the server response time. Therefore, when combining nginx with expressJS, do you use compression in express or compression in nginx? Or it simply doesn't matter!?

I know it may be opinion based, but I really wanted some feedback on this. Thanks in advance


Solution

  • NGINX supports also somewhat superior Brotli compression (aside from gzip), via 3rd party module. So having all compression done in NGINX makes more sense.

    TTFB should not be affected if you keep both (NGINX will figure out that the response is already compressed). But for that same reason (NGINX receiving an already compressed response), you won't be able to add Brotli compression support to it (if you keep it in expressJS), because the Brotli compression module expects an uncompressed response to work with.