Comments weigh in?


Viewed 466 times


Comments weigh?

I leave comments throughout my code, will influence something on the site?

I’m saying more specifically in HTML, CSS, Javascript, PHP.

3 answers


Weigh them down, but you probably use one mini-caster, right? Then they disappear and no longer weigh.

They would weigh if they were present because it’s more content to traffic not only slightly increasing the user’s waiting time, but also consuming bandwidth that someone has to pay for. It may not be much, but if you serve millions of pages (it makes a difference to you, less to those who receive). Customer processing also weighs since all of this needs to be interpreted. But it is tiniest because it will only weigh in the initial phase of interpretation which is already a very low consumption.

In PHP also weighs by interpretation, each character has to be interpreted. But also after doing the Parsing weightless.

In compiled languages do not weigh. As well as spaces and anything that sum up in the compilation. They even weigh, but will not affect the performance of the execution, weigh in the compilation process, and will be tiny also, in general imperceptible because even in exaggeration should be a difference well below 0.001%.

So use comments where you really need them to make understanding easier and minify afterwards to take that derisory weight. But first make a readable code that you’ll hardly need any comments. Organize your code so everyone can read well, learn to do this because it is easy, gives results and shows professionalism.

There is a myth that good code is code full of comments. It’s actually the opposite of that. The more comments, the more bad the code is. Of course there are cases where the comment is necessary because it cannot be expressed all the complexity of a problem in code. In general comments should tell you why and not what you’re doing. If you have to write what, change the code to be more readable.


  • You said "minificador" I sometimes even think about using, but I’m afraid of the same "spoil" my code, remove something, etc... Put already happened of I use with Javascript and it stops working. So I never use, and maybe it’s a mistake my this, not using.

  • 5

    It’s because you used a bad one. Or the JS already had problems and the mini-feeder just exposed more easily.

  • Do you recommend any? Which is good for all types of languages?

  • 1

    In the link that I posted has a list of them.

  • I saw, thank you very much!


Having HTML as the basis for sure they will weigh, however it can be an insignificant difference.

You can use some Preprocessor to compress your site before sending it to production, so the Script will remove all comments.

Depending on the maturity of your application this is not necessary as you will be worrying about something that in practice will not bring visible results to the user. Because the difference at the end will be a few kb, or even that.

  • Thank you, Mauricio, thank you! "You can use some Preprocessor to compress your site before sending it to production, so the Script will remove all comments." In case I wanted to keep the comments, for better editing later, if necessary. Better editing, I mean, be easier to locate myself. But then the recommended is to have no comments?

  • 1

    You will have two codes. One that will send to the server and one that will use for editing. Before sending to the server you can use Gulp to copy your files by removing comments

  • I understand what you mean. Thank you very much!


Each character contributes to the weight of the file, but to negatively influence the performance has to write muuuuito, so comment freely. The comments are very helpful when we are doing code maintenance. Visually they do not influence the site or system, they do not appear.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.