Question

In a NodeJS application, is there any benefit to using minified source code server-side?

The only benefit I could come up with, is that the smaller JS files would probably be loaded slightly faster from disk. But that seems negligible given that it would only impact startup time.

So, would there be any reason to process our source through uglify or closure compiler before deploying it to our production servers?

Was it helpful?

Solution

The point of minification is reducing bandwith (smaller file = less bytes). Since you're not sending your sever-side code to your client, there's no reason to reduce it. True, reading the file from disk will be a tiny bit faster, but if startup time is your bottleneck, you've got some bigger problems.

Having said that, closure compiler isn't only a minifier: it attempts to be a javascript compiler, trying speed up your code. The different JITs might also like your "compiled" code better, especially in function inlining. Having said that, the speed difference will likely be negligible.

In conclusion: No, but you might enjoy reaping the side-effects. I don't know of any tests, so you could be a pioneer in the field. Benchmark your unminified program over some time, then benchmark the minified version.

OTHER TIPS

Yes.

It will reduce startup time, because node.js is loading them and parsing them every time process starts.

But the benefit of this is marginal. If you're writing a server, you shouldn't even bother doing this, because servers are started only once and are working for a long time.

However, if you're writing a large CLI application (package managers like yapm or bower or component are great examples of that), there is a chance that you will be able to reduce startup time substantially. It's not only because of minification, but primarily because of bundling and saving require() fs hits. Minification by itself doesn't bring much though.

Anyway, try to compile your app with nexe and find out for yourself. There is a chance that you won't get any benefit out of it, but at least you'll know it. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top