Last Updated: September 29, 2021
·
1.382K
· mcloide

Always close your comments

This is a simple tip for javascript but it makes a hell lot of sense when you dealing with compressed javascript.

If you have a comment set like this:

// comment here
function very_important() {...}

Whenever it is compressed it will automatically comment the very_important function breaking the rest of the functionality.

So to avoid this kind of issues, use comments in javascript as:

/* comment here */

this will close the comment and whenever is compressed it will avoid to commenting out things that weren't supposed to.

4 Responses
Add your response

That means your compression is broken, it should be stripping comments. If all it's doing is joining lines it's not doing its job.

over 1 year ago ·

@shawncplus is exactly right. A JS compressor should always strip comments.

over 1 year ago ·

The issue was with a page compressor, not with a specific JS compressor. The page compressor did not remove any type of comment what-so-ever, as you both correctly mentioned, it should.

Thanks for your suggestions we (the team here) have reviewed the page compressor, but just in case we forgot it in some page, we also closed the comments :)

over 1 year ago ·

What type of compression are you using? Don't minifiers strip all the comments? This sounds like a bug in your compression process.

over 1 year ago ·