19

In Browsers minifying and concating or loading asynchronous JavaScript has a positive performance impact. Is this also true for code running in Node.js?

As Example would excessive commenting and using long names for properties of classes that are instantiated often impact performance and memory usage significantly?

Kai
  • 228
  • 3
  • 9

1 Answers1

39

Yes, it improves compile-time performance, but compile-time is so insignificant to the overall lifetime of your process that it shouldn't matter. The only difference would be if you're constantly starting and stopping node programs for some weird reason, which if you're doing, is probably wrong.

You won't want to uglify your server-side code, however, because if you get an error back, you'll want to know where in your human-readable code it is to find it and fix it.

I bet the real question is: Do you think the almost insignificant compile-time performance will offset the time it saves to debug your code instead?

The answer to that would be no, just stick with normal human-readable Javascript instead.

EhevuTov
  • 20,205
  • 16
  • 66
  • 71
  • 1
    I minify server side NodeJS code, because some of my installations are hosted on my clients servers. It's really mostly about protecting your code in a small way. – Spock Jun 22 '14 at 14:09
  • 1
    @Spock is that one of your standard practices or is it industry wide in the world of node/js? Are the clients ok with it? And what happens when they say something did not work and they give you the "stack trace"? – Vee6 Oct 22 '15 at 16:39
  • 4
    @Vee6> I absolutely would not recommend doing it in general. It is absolutely not something that is widely used, and there really aren't any benefits. If something doesn't work, I never debug in production code. But you are right that it could affect the use of stack traces. So: don't minify server code unless someone told you to (like in my case) – Spock Oct 23 '15 at 15:47
  • Hi all, Actually I'm curious about minifying node files. Can you guys show me the correct path to minify the node files? I searched a lot but they all are suggesting uglifyJs, which didn't work for me. – Kaushick Gope Jul 06 '16 at 12:24
  • 4
    "if you're constantly starting and stopping node programs for some weird reason" i know this answer is old but now functions as a service like aws lambda are widely used, and a not so often executed function (implying cold starts) will have to compile the node code very often – Cinn Jan 10 '19 at 15:18
  • "if you're constantly starting and stopping node programs for some weird reason" one word: autoscaling! For debugging we use source maps! Also for the performance the improvement is significant. – Melchia Dec 29 '22 at 10:04