Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should one minify server code when it's in production? [closed]

When it comes to the frontend code you always minify it (remove white spaces, comments etc) in production.

Should one do the same with server code? I usually have a lot of comments in my server files. But I have never heard about people doing so.

Wouldn't the server run faster if the code was optimized in the same way?

like image 951
ajsie Avatar asked Jul 25 '11 01:07

ajsie


People also ask

When should you minify a code?

Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.

Should you minify server code?

So, no, minifying your server side code is basically useless, worse, it's probably going to make stack traces completely useless, as there's going to be a lot of code in the same line (and not necessarily with the same formatting you used). You can minify the code and keep function names intact, preserving stack trace.

Why should you minify your JavaScript scripts before publishing them?

These characters include whitespaces, line breaks, comments, and block delimiters which are useful for us humans but unnecessary for machines. We minify the files of a website containing CSS, HTML, and Javascript code so your web browser can read them faster.


2 Answers

You're not going to have any improvement as the whitespaces and all formatting are lost when your server side code is translated to machine code (or interpreted). It's also not sent over the wire, it's read from the local filesystem, so while having less characters would lead to a faster startup, it would not make any difference on the long run and the startup speed gain would be marginal (or even unnoticeable).

So, no, minifying your server side code is basically useless, worse, it's probably going to make stack traces completely useless, as there's going to be a lot of code in the same line (and not necessarily with the same formatting you used).

like image 112
Maurício Linhares Avatar answered Sep 20 '22 11:09

Maurício Linhares


I think that minification has more to do with reducing bytes on the wire than it does runtime efficiency.

like image 45
duffymo Avatar answered Sep 21 '22 11:09

duffymo